Advertisement
fptf8fpt2018

Untitled

Jun 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.86 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3.  
  4. /*
  5. * To change this license header, choose License Headers in Project Properties.
  6. * To change this template file, choose Tools | Templates
  7. * and open the template in the editor.
  8. */
  9.  
  10. /**
  11. *
  12. * @author DELL
  13. */
  14. public class Exam1_bai1 extends javax.swing.JFrame {
  15.  
  16. /**
  17. * Creates new form Exam1_bai1
  18. */
  19. public Exam1_bai1() {
  20. initComponents();
  21. setResizable(false);
  22. setLocationRelativeTo(this);
  23. }
  24.  
  25. /**
  26. * This method is called from within the constructor to initialize the form.
  27. * WARNING: Do NOT modify this code. The content of this method is always
  28. * regenerated by the Form Editor.
  29. */
  30. @SuppressWarnings("unchecked")
  31. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  32. private void initComponents() {
  33.  
  34. buttonGroup1 = new javax.swing.ButtonGroup();
  35. jLabel1 = new javax.swing.JLabel();
  36. jRadioButton1 = new javax.swing.JRadioButton();
  37. jRadioButton2 = new javax.swing.JRadioButton();
  38. jRadioButton3 = new javax.swing.JRadioButton();
  39. jButton1 = new javax.swing.JButton();
  40.  
  41. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  42.  
  43. jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  44. jLabel1.setText("FPT UNIVERSITY");
  45.  
  46. buttonGroup1.add(jRadioButton1);
  47. jRadioButton1.setText("Red");
  48. jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
  49. public void actionPerformed(java.awt.event.ActionEvent evt) {
  50. jRadioButton1ActionPerformed(evt);
  51. }
  52. });
  53.  
  54. buttonGroup1.add(jRadioButton2);
  55. jRadioButton2.setText("Green");
  56. jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
  57. public void actionPerformed(java.awt.event.ActionEvent evt) {
  58. jRadioButton2ActionPerformed(evt);
  59. }
  60. });
  61.  
  62. buttonGroup1.add(jRadioButton3);
  63. jRadioButton3.setText("Blue");
  64. jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
  65. public void actionPerformed(java.awt.event.ActionEvent evt) {
  66. jRadioButton3ActionPerformed(evt);
  67. }
  68. });
  69.  
  70. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  71. getContentPane().setLayout(layout);
  72. layout.setHorizontalGroup(
  73. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74. .addGroup(layout.createSequentialGroup()
  75. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  76. .addGroup(layout.createSequentialGroup()
  77. .addGap(87, 87, 87)
  78. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
  79. .addGroup(layout.createSequentialGroup()
  80. .addGap(108, 108, 108)
  81. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
  82. .addGroup(layout.createSequentialGroup()
  83. .addGap(47, 47, 47)
  84. .addComponent(jRadioButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
  85. .addGap(35, 35, 35)
  86. .addComponent(jRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
  87. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  88. .addComponent(jRadioButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
  89. .addContainerGap(90, Short.MAX_VALUE))
  90. );
  91. layout.setVerticalGroup(
  92. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93. .addGroup(layout.createSequentialGroup()
  94. .addGap(42, 42, 42)
  95. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
  96. .addGap(53, 53, 53)
  97. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  98. .addComponent(jRadioButton1)
  99. .addComponent(jRadioButton2)
  100. .addComponent(jRadioButton3))
  101. .addGap(42, 42, 42)
  102. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  103. .addContainerGap(34, Short.MAX_VALUE))
  104. );
  105.  
  106. pack();
  107. }// </editor-fold>
  108.  
  109. private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  110. jButton1.setText("RED");
  111. jButton1.setBackground(Color.red);
  112. jLabel1.setForeground(Color.red);
  113. }
  114.  
  115. private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  116. jButton1.setText("GREEN");
  117. jButton1.setBackground(Color.green);
  118. jLabel1.setForeground(Color.green);
  119. }
  120.  
  121. private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  122. jButton1.setText("BLUE");
  123. jButton1.setBackground(Color.blue);
  124. jLabel1.setForeground(Color.blue);
  125. }
  126.  
  127. /**
  128. * @param args the command line arguments
  129. */
  130. public static void main(String args[]) {
  131. /* Set the Nimbus look and feel */
  132. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  133. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  134. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  135. */
  136. try {
  137. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  138. if ("Nimbus".equals(info.getName())) {
  139. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  140. break;
  141. }
  142. }
  143. } catch (ClassNotFoundException ex) {
  144. java.util.logging.Logger.getLogger(Exam1_bai1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  145. } catch (InstantiationException ex) {
  146. java.util.logging.Logger.getLogger(Exam1_bai1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  147. } catch (IllegalAccessException ex) {
  148. java.util.logging.Logger.getLogger(Exam1_bai1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  149. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  150. java.util.logging.Logger.getLogger(Exam1_bai1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  151. }
  152. //</editor-fold>
  153.  
  154. /* Create and display the form */
  155. java.awt.EventQueue.invokeLater(new Runnable() {
  156. public void run() {
  157. new Exam1_bai1().setVisible(true);
  158. }
  159. });
  160. }
  161.  
  162. // Variables declaration - do not modify
  163. private javax.swing.ButtonGroup buttonGroup1;
  164. private javax.swing.JButton jButton1;
  165. private javax.swing.JLabel jLabel1;
  166. private javax.swing.JRadioButton jRadioButton1;
  167. private javax.swing.JRadioButton jRadioButton2;
  168. private javax.swing.JRadioButton jRadioButton3;
  169. // End of variables declaration
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement