Advertisement
thecodesalim

java swing

Sep 23rd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. /**
  6. *
  7. * @author SalimMatazu
  8. */
  9. public class ColorChangerApp extends javax.swing.JFrame{
  10. ColorModel model = new ColorModel();
  11.  
  12. /**
  13. * Creates new form ColorChangerApp
  14. */
  15. public ColorChangerApp() {
  16. initComponents();
  17. btn1.addActionListener(model);
  18. }
  19.  
  20. /**
  21. * This method is called from within the constructor to initialize the form.
  22. * WARNING: Do NOT modify this code. The content of this method is always
  23. * regenerated by the Form Editor.
  24. */
  25. @SuppressWarnings("unchecked")
  26. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  27. private void initComponents() {
  28.  
  29. panel = new javax.swing.JPanel();
  30. btn1 = new javax.swing.JButton();
  31. btn2 = new javax.swing.JButton();
  32. btn3 = new javax.swing.JButton();
  33.  
  34. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  35.  
  36. btn1.setText("BLUE");
  37.  
  38. btn2.setText("RED");
  39.  
  40. btn3.setText("GREEN");
  41.  
  42. javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
  43. panel.setLayout(panelLayout);
  44. panelLayout.setHorizontalGroup(
  45. panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  46. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
  47. .addGap(14, 14, 14)
  48. .addComponent(btn1)
  49. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
  50. .addComponent(btn2)
  51. .addGap(79, 79, 79)
  52. .addComponent(btn3)
  53. .addContainerGap())
  54. );
  55. panelLayout.setVerticalGroup(
  56. panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  57. .addGroup(panelLayout.createSequentialGroup()
  58. .addGap(156, 156, 156)
  59. .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  60. .addComponent(btn3)
  61. .addComponent(btn2)
  62. .addComponent(btn1))
  63. .addContainerGap(115, Short.MAX_VALUE))
  64. );
  65.  
  66. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  67. getContentPane().setLayout(layout);
  68. layout.setHorizontalGroup(
  69. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70. .addComponent(panel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  71. );
  72. layout.setVerticalGroup(
  73. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74. .addComponent(panel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  75. );
  76.  
  77. pack();
  78. }// </editor-fold>
  79.  
  80. /**
  81. * @param args the command line arguments
  82. */
  83. public static void main(String args[]) {
  84. /* Set the Nimbus look and feel */
  85. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  86. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  87. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  88. */
  89. try {
  90. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  91. if ("Nimbus".equals(info.getName())) {
  92. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  93. break;
  94. }
  95. }
  96. } catch (ClassNotFoundException ex) {
  97. java.util.logging.Logger.getLogger(ColorChangerApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  98. } catch (InstantiationException ex) {
  99. java.util.logging.Logger.getLogger(ColorChangerApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  100. } catch (IllegalAccessException ex) {
  101. java.util.logging.Logger.getLogger(ColorChangerApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  102. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  103. java.util.logging.Logger.getLogger(ColorChangerApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  104. }
  105. //</editor-fold>
  106.  
  107. /* Create and display the form */
  108. java.awt.EventQueue.invokeLater(new Runnable() {
  109. public void run() {
  110. new ColorChangerApp().setVisible(true);
  111. }
  112. });
  113. }
  114.  
  115. // Variables declaration - do not modify
  116. private javax.swing.JButton btn1;
  117. private javax.swing.JButton btn2;
  118. private javax.swing.JButton btn3;
  119. private javax.swing.JPanel panel;
  120. // End of variables declaration
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement