Tampilan frame atau lebih dikenal dengan “Look and Feel” di java
dapat diatur sesuai keinginan kita. Java memiliki 3 Look and Feel dasar
yaitu Metal, Motif dan Windows.
Dan berikut ini contoh tampilannya:
Berikut ini program lengkapnya:
003 | import java.awt.event.*; |
009 | public class LookAndFeelDemo extends JFrame { |
011 | private final String lookName[] = { "Metal" , "Motif" , "Windows" }; |
013 | private UIManager.LookAndFeelInfo lookr[]; |
015 | private JRadioButton rdLook[]; |
017 | private ButtonGroup btnGroup; |
021 | private JTextField txt; |
023 | private JPanel panel1, panel2; |
027 | public LookAndFeelDemo () { |
029 | super ( "Look and Feel Demo : Tampilan Frame" ); |
035 | Container container = getContentPane(); |
037 | ItemHandler handler = new ItemHandler (); |
039 | panel1 = new JPanel(); |
041 | panel2 = new JPanel(); |
045 | btnGroup = new ButtonGroup(); |
049 | rdLook = new JRadioButton [lookName.length]; |
051 | for ( int i = 0 ; i < rdLook.length; i++) { |
053 | rdLook[i] = new JRadioButton (lookName[i]); |
055 | rdLook[i].addItemListener(handler); |
057 | btnGroup.add(rdLook[i]); |
059 | panel2.add(rdLook[i]); |
065 | btn = new JButton ( "Tombol" ); |
067 | txt = new JTextField ( 20 ); |
077 | container.add(panel1, BorderLayout.NORTH); |
079 | container.add(panel2, BorderLayout.SOUTH); |
083 | looks = UIManager.getInstalledLookAndFeels(); |
087 | setLocationRelativeTo ( null ); |
095 | private void changeLookAndFeel( int val) { |
099 | UIManager.setLookAndFeel(looks[val].getClassName()); |
101 | SwingUtilities.updateComponentTreeUI( this ); |
}
105 | catch (Exception ex) { |
107 | ex.printStackTrace(); |
115 | public static void main (String args[]) { |
117 | LookAndFeelDemo test = new LookAndFeelDemo(); |
119 | test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
125 | private class ItemHandler implements ItemListener { |
127 | public void itemStateChanged (ItemEvent e) { |
131 | for ( int i = 0 ; i < rdLook.length; i++) { |
133 | if (rdLook[i].isSelected()) { |
135 | changeLookAndFeel (i); |
0 :
Posting Komentar