Java Panels and layouts
tonyn | November 13, 2008Panels
Panels are rectangular components, which serve two main purpose:
1. they can be used as canvas that one draws on
2. they can be used as containers to embed further graphical components
Panels
Panels are rectangular components, which serve two main purpose:
1. they can be used as canvas that one draws on
2. they can be used as containers to embed further graphical components
Category |
Listener type name |
Method defined |
| Action | ActionListener | void actionPerformed(ActionEvent e) |
| Adjustment | AdjustmentListener | void adjustmentValueChanged(AdjustmentEvent e) |
| Component | ComponentListener | void componentHidden(ComponentEvent e) void componentMoved(ComponentEvent e) void componentResized(ComponentEvent e) void componentShown(ComponentEvent e) |
| Container | ContainerListener | void componentAdded(ContainerEvent e) void componentRemoved(ContainerEvent e) |
| Focus | FocusListener | void focusGained(FocusEvent e) void focusLost(FocusEvent e) |
| Item | ItemListener | void itemStateChanged(ItemEvent e) |
| Key | KeyListener | void keyPressed(KeyEvent e) void keyReleased(KeyEvent e) void keyTyped(KeyEvent e) |
| Mouse | MouseListener | void mouseClicked(MouseEvent e) void mouseEntered(MouseEvent e) void mouseExited(MouseEvent e) void mousePressed(MouseEvent e) void mouseReleased(MouseEvent e) |
| Mouse motion | MouseMotionListener | void mouseDragged(MouseEvent e) void mouseMoved(MouseEvent e) |
| Text | TextListener | void textValueChanged(TextEvent e) |
| Window | WindowListener | void windowActivated(WindowEvent e) void windowClosed(WindowEvent e) void windowClosing(WindowEvent e) void windowDeactivated(WindowEvent e) void windowDeiconified(WindowEvent e) void windowIconified(WindowEvent e) void windowOpened(WindowEvent e) |
The definition of the handler class:
[public] class class-name [extends superclass-name] implements ActionListener {
….
public void actionPerformed(ActionEvent ae) {
….
}
}
public JLabel(String text)
public JLabel(ImageIcon picture)
public String getText()
public void setText(String text)
public void setText(String text, int alignment)
public void setForeground(Color c)
public void setBackground(Color c)
public void setOpaque(boolean b)
-
getText() returns the text currently displayed in the label as a String.
setText(String text, int alignment) alignment=SwingConstants.CENTER, LEFT, RIGHT
setOpaque(boolean b) Set non-transparent, transparent
JFrame()
setVisible(boolean b)
setTitle(String title)
setSize(int width, int height)
setLocation(int horizontal, int vertical)
pack()
setDefaultCloseOperation(int operation)
pack() resizes the frame so that it tightly fits around components embedded into its content pane.
1. Creating a top-level container object
2. Creating GUI components and adding them to the top-level container
3. Adding the functionalities to the GUI components
Swing - Java Foundation Classes http://java.sun.com/javase/6/docs/technotes/guides/swing/
Java Swing http://www.javaswing.net/
A Swing Architecture Overview http://java.sun.com/products/jfc/tsc/articles/architecture/
Drag and Drop http://java.sun.com/javase/6/docs/technotes/guides/dragndrop/
Java 3D https://java3d.dev.java.net/
J3D.org http://java3d.j3d.org/
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | ||