Java -Thực hành về JLabel - JButton
package thanhcs.blogspot.com; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; public class GUIDEMO extends JFrame implements ActionListener{ JPanel mJpanel; JLabel mjLabel; JButton btnOK, btnCancel; public GUIDEMO() { setLayout(new BorderLayout()); mjLabel = new JLabel("Continues ?",SwingConstants.CENTER); mjLabel.setForeground(Color.red); add(mjLabel,BorderLayout.CENTER); mJpanel = new JPanel(); mJpanel.add(btnOK = new JButton("OK")); mJpanel.add(btnCancel = new JButton("Cancel")); btnCancel.addActionListener(this); add(mJpanel, BorderLayout.SOUTH); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(300, 100); setLocationRelativeTo(null); } @Override public void actionPerformed(ActionEvent arg0) { System.exit(0); } }
test.java
package thanhcs.blogspot.com; public class test { public static void main(String[] args) { GUIDEMO a = new GUIDEMO(); } }
And result :
No comments: