import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ShowColors2 extends JFrame { private JButton tblUbah; private Color warna = Color.LIGHT_GRAY; private Container container; //atur tampilan GUI public ShowColors2() { super ("Menggunakan JColorChooser"); container = getContentPane(); container.setLayout (new FlowLayout()); //atur event pd tombol tblUbah tblUbah = new JButton ("Ubah Warna"); tblUbah.addActionListener ( new ActionListener() { public void actionPerformed (ActionEvent event) { warna = JColorChooser.showDialog ( ShowColors2.this, "Pilih Warna", warna); if (warna == null) warna = Color.LIGHT_GRAY; container.setBackground (warna); } } //end of inner class ); //end of method addActionListener container.add (tblUbah); setSize (400,300); setVisible (true); } //end of constructor public static void main (String args[]) { ShowColors2 test = new ShowColors2(); test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } }
Program JColorChooser di Java
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment