Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.JOptionPane;
  4. import javax.swing.JRadioButton;
  5. import javax.swing.JTextField;
  6.  
  7. import java.awt.Color;
  8. import java.awt.Cursor;
  9. import java.awt.GridBagLayout;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12.  
  13. import javax.swing.JButton;
  14. import javax.swing.JComboBox;
  15.  
  16. public class Main {
  17.  
  18. private static JTextField textField;
  19. private static JButton CATbutton2;
  20. private static JButton CATbutton3;
  21. private static JRadioButton radioButton1;
  22. private static JRadioButton radioButton2;
  23. private static JRadioButton radioButton3;
  24. private static JComboBox combobox;
  25.  
  26. public static void main(String[] args) {
  27. JFrame frame = new JFrame();
  28. frame.setSize(800, 400);
  29. frame.setTitle("I LOVE MY CAT");
  30. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. frame.setLocationRelativeTo(null);
  32. frame.setLayout(new GridBagLayout());
  33.  
  34. textField = new JTextField(10);
  35.  
  36. frame.add(textField);
  37.  
  38. combobox = new JComboBox();
  39. combobox.setEditable(true);
  40.  
  41. JButton CATbutton = new JButton();
  42. CATbutton.setText("CLICK HERE");
  43. CATbutton.setBackground(Color.PINK);
  44. CATbutton.setForeground(Color.DARK_GRAY);
  45.  
  46. Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
  47.  
  48. CATbutton.setCursor(cursor);
  49.  
  50. CATbutton.addActionListener(new ButtonActionListener());
  51.  
  52. CATbutton2 = new JButton();
  53. CATbutton2.setText("BUTTON2");
  54. CATbutton2.setCursor(cursor);
  55.  
  56. CATbutton2.addActionListener(new Button2ActionListener());
  57.  
  58. CATbutton3 = new JButton();
  59. CATbutton3.setText("BUTTON3");
  60. CATbutton3.setCursor(cursor);
  61.  
  62. CATbutton3.addActionListener(new Button3ActionListener());
  63.  
  64. radioButton1 = new JRadioButton("My cat");
  65. radioButton2 = new JRadioButton("Her cat");
  66. radioButton3 = new JRadioButton("Ur cat");
  67.  
  68. JButton CATbutton4 = new JButton();
  69. CATbutton4.setText("CLICK");
  70. CATbutton4.setCursor(cursor);
  71.  
  72. CATbutton4.addActionListener(new Button4ActionListener());
  73.  
  74. frame.add(combobox);
  75.  
  76. frame.add(CATbutton3);
  77.  
  78. frame.add(CATbutton2);
  79.  
  80. frame.add(CATbutton);
  81.  
  82. frame.add(radioButton1);
  83.  
  84. frame.add(radioButton2);
  85.  
  86. frame.add(radioButton3);
  87.  
  88. frame.add(CATbutton4);
  89.  
  90. frame.setVisible(true);
  91.  
  92. }
  93.  
  94. public static class ButtonActionListener implements ActionListener {
  95.  
  96. @Override
  97. public void actionPerformed(ActionEvent event) {
  98.  
  99. String str = textField.getText();
  100. if (str.compareTo(combobox.toString()) == 0){
  101. JOptionPane.showMessageDialog(null, "ERROR");
  102. }
  103. else {
  104.  
  105. combobox.addItem(str);
  106. }
  107.  
  108. /* JFrame frame2 = new JFrame();
  109. frame2.setSize(400, 200);
  110. frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  111. frame2.setLocationRelativeTo(null);
  112. frame2.setLayout(new GridBagLayout());
  113.  
  114. JLabel label = new JLabel();
  115.  
  116. label.setText(str);
  117. frame2.add(label);
  118.  
  119. frame2.setVisible(true); */
  120.  
  121. }
  122. }
  123.  
  124. public static class Button2ActionListener implements ActionListener {
  125.  
  126. @Override
  127. public void actionPerformed(ActionEvent event) {
  128. String str1 = textField.getText();
  129. CATbutton3.setText(str1);
  130.  
  131. }
  132. }
  133.  
  134. public static class Button3ActionListener implements ActionListener {
  135.  
  136. @Override
  137. public void actionPerformed(ActionEvent event) {
  138. String str2 = CATbutton2.getText();
  139. String str3 = CATbutton3.getText();
  140. CATbutton3.setText(str2);
  141. CATbutton2.setText(str3);
  142.  
  143. }
  144. }
  145.  
  146. public static class Button4ActionListener implements ActionListener {
  147. @Override
  148. public void actionPerformed(ActionEvent event) {
  149. String str = textField.getText();
  150. if (str.compareTo(radioButton1.getText()) == 0) {
  151. radioButton1.setSelected(true);
  152. }
  153.  
  154. else if (str.compareTo(radioButton2.getText()) == 0) {
  155. radioButton2.setSelected(true);
  156. } else if (str.compareTo(radioButton3.getText()) == 0) {
  157. radioButton3.setSelected(true);
  158. } else {
  159. JOptionPane.showMessageDialog(null, "ERROR");
  160.  
  161. //joptionpane
  162. /* JFrame frame3 = new JFrame("ERROR");
  163. frame3.setSize(400, 200);
  164. frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  165. frame3.setLocationRelativeTo(null);
  166. frame3.setLayout(new GridBagLayout());
  167.  
  168. JLabel label1 = new JLabel();
  169.  
  170. label1.setText("Error! The word doesn't exist.");
  171. label1.setForeground(Color.getHSBColor(360, 100, 88));
  172. // label1.setFont(new Font("Dialog, Font.PLAIN, 14"));
  173.  
  174. frame3.add(label1);
  175.  
  176. frame3.setVisible(true); */
  177.  
  178. }
  179.  
  180. }
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement