Intro
MVC Pattern
Basic Components
Layoutmanager
Example: Basic Swing App
public class BasicFrame extends JFrame implements ActionListener {
// ...
@Override
public void actionPerformed(ActionEvent event) {
// ...
}
}
// JFrame class in JSE
public class JFrame extends Frame implements ... {
// ...
}
// Content pane as container
JPanel namePanel = new JPanel();
namePanel.setBorder(BorderFactory.createEtchedBorder());
getContentPane().add(namePanel, BorderLayout.NORTH);
// JPanel class in JSE
public class JPanel extends JComponent implements ... {
// ...
}
// Usage
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEtchedBorder());
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
// JLabel class in JSE
public class JLabel extends JComponent implements ... {
// ...
}
// JTextField class in JSE
public class JTextField extends JTextComponent implements ... {
// ...
}
// JLabel usage
JLabel nameLabel = new JLabel("Name: ", new ImageIcon("triblue.gif"), SwingConstants.LEFT);
// JTextField usage
JTextField tf = new JTextField(30);
// Tooltip on JButton
JButton btn1 = new JButton("Metal");
btn1.setToolTipText("Activate Metal-Look-and-Feel");
// Borders
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEtchedBorder());
String[] MONTHS = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December",
};
JList list = new JList(MONTHS);
JList list = new JList(MONTHS);
list.setToolTipText("Choose your birthdate");
getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
Handbuch der Java-Programmierung
(5. Auflage)
Thank you for your attention!