1. package szut.org.ColorChange;
  2. import java.awt.BorderLayout;
  3. import java.awt.Color;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.BorderFactory;
  7. import javax.swing.JButton;
  8. import javax.swing.JSeparator;
  9. import javax.swing.JTextArea;
  10. import javax.swing.JTextField;
  11.  
  12. import javax.swing.WindowConstants;
  13. import javax.swing.border.LineBorder;
  14. import javax.swing.SwingUtilities;
  15.  
  16.  
  17. /**
  18. * This code was edited or generated using CloudGarden's Jigloo
  19. * SWT/Swing GUI Builder, which is free for non-commercial
  20. * use. If Jigloo is being used commercially (ie, by a corporation,
  21. * company or business for any purpose whatever) then you
  22. * should purchase a license for each developer using Jigloo.
  23. * Please visit www.cloudgarden.com for details.
  24. * Use of Jigloo implies acceptance of these licensing terms.
  25. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
  26. * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
  27. * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
  28. */
  29. public class ColorChange extends javax.swing.JFrame {
  30. private JTextField txtFieldColor;
  31. private JSeparator jSeparator1;
  32. private JTextArea colorTxtArea;
  33. private JButton colorButton;
  34.  
  35. /**
  36. * Auto-generated main method to display this JFrame
  37. */
  38. public static void main(String[] args) {
  39. SwingUtilities.invokeLater(new Runnable() {
  40. public void run() {
  41. ColorChange inst = new ColorChange();
  42. inst.setLocationRelativeTo(null);
  43. inst.setVisible(true);
  44. }
  45. });
  46. }
  47.  
  48. public ColorChange() {
  49. super();
  50. initGUI();
  51. }
  52.  
  53. private void initGUI() {
  54. try {
  55. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  56. getContentPane().setLayout(null);
  57. this.setTitle("COLOOORS!");
  58. {
  59. txtFieldColor = new JTextField();
  60. getContentPane().add(txtFieldColor);
  61. txtFieldColor.setBounds(17, 227, 91, 25);
  62. }
  63. {
  64. colorButton = new JButton();
  65. getContentPane().add(colorButton);
  66. colorButton.setText("Color me!");
  67. colorButton.setBounds(279, 228, 91, 23);
  68. colorButton.addActionListener(new ActionListener() {
  69. public void actionPerformed(ActionEvent evt) {
  70. colorButtonActionPerformed(evt);
  71. }
  72. });
  73. }
  74. {
  75. colorTxtArea = new JTextArea();
  76. getContentPane().add(colorTxtArea);
  77. colorTxtArea.setBounds(17, 12, 353, 210);
  78. colorTxtArea.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
  79. }
  80. {
  81. jSeparator1 = new JSeparator();
  82. getContentPane().add(jSeparator1);
  83. jSeparator1.setBounds(0, 260, 392, 10);
  84. }
  85. pack();
  86. setSize(400, 300);
  87. } catch (Exception e) {
  88. e.printStackTrace();
  89. }
  90. }
  91.  
  92. private void colorButtonActionPerformed(ActionEvent evt) {
  93. System.out.println("colorButton.actionPerformed, event="+evt);
  94. String s = txtFieldColor.getText();
  95. if(s.equals("Blau")){
  96. colorTxtArea.setBackground(new Color (0, 128, 255));
  97. }else if(s.equals("Rot")){
  98. colorTxtArea.setBackground(new Color (255, 0, 0));
  99. }else if(s.equals("Grün")){
  100. colorTxtArea.setBackground(new Color (0, 255, 0));
  101. }else{
  102. s.equals("Rot");colorTxtArea.setBackground(new Color (0, 128, 255));
  103. }
  104. }
  105.  
  106. }
  107.