Contoh Program Mengatur Tampilan Frame di Java

Minggu, 15 Januari 2012

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. Selain itu banyak tersedia Look and Feel di internet yang dapat didownload secara gratis. Berikut ini contoh program yang mengatur tampilan atau tema dan frame.
Dan berikut ini contoh tampilannya:

Berikut ini program lengkapnya:
001import java.awt.*;
002 
003import java.awt.event.*;
004 
005import javax.swing.*;
006 
007public class LookAndFeelDemo extends JFrame {
008 
009    private final String lookName[] = {"Metal", "Motif", "Windows"};
010 
011    private UIManager.LookAndFeelInfo looks[];
012 
013    private JRadioButton rdLook[];
014 
015    private ButtonGroup btnGroup;
016 
017    private JButton btn;
018 
019    private JTextField txt;
020 
021    private JPanel panel1, panel2;
022 
023    public LookAndFeelDemo () {
024 
025        super ("Look and Feel Demo : Tampilan Frame");
026 
027        setSize (400,300);
028 
029        Container container = getContentPane();
030 
031        ItemHandler handler = new ItemHandler ();
032 
033        panel1 = new JPanel();
034 
035        panel2 = new JPanel();
036 
037        btnGroup = new ButtonGroup();
038 
039        rdLook = new JRadioButton [lookName.length];
040 
041        for (int i = 0; i < rdLook.length; i++) {
042 
043            rdLook[i] = new JRadioButton (lookName[i]);
044 
045            rdLook[i].addItemListener(handler);
046 
047            btnGroup.add(rdLook[i]);
048 
049            panel2.add(rdLook[i]);
050 
051        }
052 
053        btn = new JButton ("Tombol");
054 
055        txt = new JTextField (20);
056 
057        panel1.add(btn);
058 
059        panel1.add(txt);
060 
061        container.add(panel1, BorderLayout.NORTH);
062 
063        container.add(panel2, BorderLayout.SOUTH);
064 
065        looks = UIManager.getInstalledLookAndFeels();
066 
067        setLocationRelativeTo (null);
068 
069        setVisible (true);
070 
071    }
072 
073    private void changeLookAndFeel(int val) {
074 
075        try {
076 
077            UIManager.setLookAndFeel(looks[val].getClassName());
078 
079            SwingUtilities.updateComponentTreeUI(this);
080 
081        }
082 
083        catch (Exception ex) {
084 
085            ex.printStackTrace();
086 
087        }
088 
089    }
090 
091    public static void main (String args[]) {
092 
093        LookAndFeelDemo test = new LookAndFeelDemo();
094 
095        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
096 
097    }
098 
099    private class ItemHandler implements ItemListener {
100 
101        public void itemStateChanged (ItemEvent e) {
102 
103            //
104 
105            for (int i = 0; i < rdLook.length; i++) {
106 
107                if (rdLook[i].isSelected()) {
108 
109                    changeLookAndFeel (i);
110 
111                }
112 
113            }
114 
115        }
116 
117    }
118 
119}
Semoga bermanfaat.

0 komentar:

Posting Komentar

Lagu Daerah Bengkulu Selatan

http://www.ziddu.com/download/17765598/PantaiPasarBawah.mp3.html
http://www.ziddu.com/download/17770609/Ading.mp3.html
http://www.ziddu.com/download/17770638/BatinLingiran.mp3.html
http://www.ziddu.com/download/17770712/BeghasKedurang.mp3.html
http://www.ziddu.com/download/17765528/MutighKupi.mp3.html
http://www.ziddu.com/download/17765460/KasiahSayang.mp3.html
http://www.ziddu.com/download/17765364/KemaneAgi.mp3.html
http://www.ziddu.com/download/17765259/KebilauBaliak.mp3.html
http://www.ziddu.com/download/17765180/KedurangBadakuDillahirka.mp3.html
http://www.ziddu.com/download/17764830/TukangKundai.mp3.html
http://www.ziddu.com/download/17764761/SukatanMatau.mp3.html
http://www.ziddu.com/download/17764705/Sinjang.mp3.html
http://www.ziddu.com/download/17764641/Seginim.mp3.html
http://www.ziddu.com/download/17764579/sekundangsetungguan.mp3.html

sumber: Radio Artha FM Bengkulu Selatan

Contoh Program Mengatur Tampilan Frame di Java


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. Selain itu banyak tersedia Look and Feel di internet yang dapat didownload secara gratis. Berikut ini contoh program yang mengatur tampilan atau tema dan frame.
Dan berikut ini contoh tampilannya:

Berikut ini program lengkapnya:
001import java.awt.*;
002 
003import java.awt.event.*;
004 
005import javax.swing.*;
006 
007public class LookAndFeelDemo extends JFrame {
008 
009    private final String lookName[] = {"Metal", "Motif", "Windows"};
010 
011    private UIManager.LookAndFeelInfo looks[];
012 
013    private JRadioButton rdLook[];
014 
015    private ButtonGroup btnGroup;
016 
017    private JButton btn;
018 
019    private JTextField txt;
020 
021    private JPanel panel1, panel2;
022 
023    public LookAndFeelDemo () {
024 
025        super ("Look and Feel Demo : Tampilan Frame");
026 
027        setSize (400,300);
028 
029        Container container = getContentPane();
030 
031        ItemHandler handler = new ItemHandler ();
032 
033        panel1 = new JPanel();
034 
035        panel2 = new JPanel();
036 
037        btnGroup = new ButtonGroup();
038 
039        rdLook = new JRadioButton [lookName.length];
040 
041        for (int i = 0; i < rdLook.length; i++) {
042 
043            rdLook[i] = new JRadioButton (lookName[i]);
044 
045            rdLook[i].addItemListener(handler);
046 
047            btnGroup.add(rdLook[i]);
048 
049            panel2.add(rdLook[i]);
050 
051        }
052 
053        btn = new JButton ("Tombol");
054 
055        txt = new JTextField (20);
056 
057        panel1.add(btn);
058 
059        panel1.add(txt);
060 
061        container.add(panel1, BorderLayout.NORTH);
062 
063        container.add(panel2, BorderLayout.SOUTH);
064 
065        looks = UIManager.getInstalledLookAndFeels();
066 
067        setLocationRelativeTo (null);
068 
069        setVisible (true);
070 
071    }
072 
073    private void changeLookAndFeel(int val) {
074 
075        try {
076 
077            UIManager.setLookAndFeel(looks[val].getClassName());
078 
079            SwingUtilities.updateComponentTreeUI(this);
080 
081        }
082 
083        catch (Exception ex) {
084 
085            ex.printStackTrace();
086 
087        }
088 
089    }
090 
091    public static void main (String args[]) {
092 
093        LookAndFeelDemo test = new LookAndFeelDemo();
094 
095        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
096 
097    }
098 
099    private class ItemHandler implements ItemListener {
100 
101        public void itemStateChanged (ItemEvent e) {
102 
103            //
104 
105            for (int i = 0; i < rdLook.length; i++) {
106 
107                if (rdLook[i].isSelected()) {
108 
109                    changeLookAndFeel (i);
110 
111                }
112 
113            }
114 
115        }
116 
117    }
118 
119}
Semoga bermanfaat.