AWT |
Swing |
import
import java.awt.*;
import javax.awt.event.*;
|
import
import javax.swing.*;
import javax.swing.event.*;
|
Frame
private Frame f = new Frame("JavaPad");
f.setMenuBar(menuBar);
f.setLayout(new BorderLayout());
f.show();
|
JFrame
private JFrame f = new JFrame("JavaPad");
f.setJMenuBar(menuBar);
Container c = f.getContentPane();
c.setLayout(new BorderLayout());
f.setVisible(true);
|
MenuBar
private MenuBar mb = new MenuBar();
mb.add(m);
|
JMenuBar
private JMenuBar mb = new JMenuBar();
mb.add(m);
|
Menu
private Menu m = new Menu("File");
m.add(mi);
|
JMenu
private JMenu m = new JMenu("File");
m.add(mi);
|
MenuItem
private MenuItem mi = new MenuItem("New");
|
JMenuItem
private JMenuItem mi = new JMenuItem("New");
|
FileDialog
private FileDialog fd = new FileDialog(f, "Open File");
private String fileName = "";
private String pathName = "";
fd.show();
if ( openFile.getFile() != null ) {
fileName = fd.getFile();
pathName = fd.getDirectory();
fr = new FileReader(pathName + fileName);
|
JFileChooser
private JFileChooser fd = new JFileChooser();
private File file = null;
fd.setCurrentDirectory(new File("d:/temp"));
int returnVal = fd.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fd.getSelectedFile();
fr = new FileReader(file);
|
TextArea
private TextArea ta = new TextArea("");
ta.addTextListener(this);
|
JTextArea
private JTextArea ta = new JTextArea("");
ta.getDocument().addDocumentListener(this);
JScrollPane asp = new JScrollPane(ta);
asp.setVerticalScrollBarPolicy(22);
c.add(asp);
|
TextField
private TextField tf = new TextField(50);
|
JTextField
private JTextField tf = new JTextField(50);
|
Label
private Label l = new Label("Search Criteria:");
|
JLabel
private JLabel l = new JLabel("Search Criteria:");
|
Panel
private Panel p = new Panel();
|
JPanel
private JPanel p = new JPanel();
|
Advantages
Less complicated to use
Less code
Fewer library dependencies
Works easily with current browsers (applet tag)
|
Advantages
Richer set of controls
|
Disadvantages
Not as rich a set of controls
|
Disadvantages
More complicated to use
More code
Extra library dependencies
Requires browser-dependent tags/plugin
|