Advertisement
Svetlana_Ovsjanikova

java - SampleGUI.source

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