Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- import java.awt.Color;
- import java.awt.Cursor;
- import java.awt.GridBagLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- public class Main {
- private static JTextField textField;
- private static JButton CATbutton2;
- private static JButton CATbutton3;
- private static JRadioButton radioButton1;
- private static JRadioButton radioButton2;
- private static JRadioButton radioButton3;
- private static JComboBox combobox;
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- frame.setSize(800, 400);
- frame.setTitle("I LOVE MY CAT");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setLayout(new GridBagLayout());
- textField = new JTextField(10);
- frame.add(textField);
- combobox = new JComboBox();
- combobox.setEditable(true);
- JButton CATbutton = new JButton();
- CATbutton.setText("CLICK HERE");
- CATbutton.setBackground(Color.PINK);
- CATbutton.setForeground(Color.DARK_GRAY);
- Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
- CATbutton.setCursor(cursor);
- CATbutton.addActionListener(new ButtonActionListener());
- CATbutton2 = new JButton();
- CATbutton2.setText("BUTTON2");
- CATbutton2.setCursor(cursor);
- CATbutton2.addActionListener(new Button2ActionListener());
- CATbutton3 = new JButton();
- CATbutton3.setText("BUTTON3");
- CATbutton3.setCursor(cursor);
- CATbutton3.addActionListener(new Button3ActionListener());
- radioButton1 = new JRadioButton("My cat");
- radioButton2 = new JRadioButton("Her cat");
- radioButton3 = new JRadioButton("Ur cat");
- JButton CATbutton4 = new JButton();
- CATbutton4.setText("CLICK");
- CATbutton4.setCursor(cursor);
- CATbutton4.addActionListener(new Button4ActionListener());
- frame.add(combobox);
- frame.add(CATbutton3);
- frame.add(CATbutton2);
- frame.add(CATbutton);
- frame.add(radioButton1);
- frame.add(radioButton2);
- frame.add(radioButton3);
- frame.add(CATbutton4);
- frame.setVisible(true);
- }
- public static class ButtonActionListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent event) {
- String str = textField.getText();
- if (str.compareTo(combobox.toString()) == 0){
- JOptionPane.showMessageDialog(null, "ERROR");
- }
- else {
- combobox.addItem(str);
- }
- /* JFrame frame2 = new JFrame();
- frame2.setSize(400, 200);
- frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame2.setLocationRelativeTo(null);
- frame2.setLayout(new GridBagLayout());
- JLabel label = new JLabel();
- label.setText(str);
- frame2.add(label);
- frame2.setVisible(true); */
- }
- }
- public static class Button2ActionListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent event) {
- String str1 = textField.getText();
- CATbutton3.setText(str1);
- }
- }
- public static class Button3ActionListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent event) {
- String str2 = CATbutton2.getText();
- String str3 = CATbutton3.getText();
- CATbutton3.setText(str2);
- CATbutton2.setText(str3);
- }
- }
- public static class Button4ActionListener implements ActionListener {
- @Override
- public void actionPerformed(ActionEvent event) {
- String str = textField.getText();
- if (str.compareTo(radioButton1.getText()) == 0) {
- radioButton1.setSelected(true);
- }
- else if (str.compareTo(radioButton2.getText()) == 0) {
- radioButton2.setSelected(true);
- } else if (str.compareTo(radioButton3.getText()) == 0) {
- radioButton3.setSelected(true);
- } else {
- JOptionPane.showMessageDialog(null, "ERROR");
- //joptionpane
- /* JFrame frame3 = new JFrame("ERROR");
- frame3.setSize(400, 200);
- frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- frame3.setLocationRelativeTo(null);
- frame3.setLayout(new GridBagLayout());
- JLabel label1 = new JLabel();
- label1.setText("Error! The word doesn't exist.");
- label1.setForeground(Color.getHSBColor(360, 100, 88));
- // label1.setFont(new Font("Dialog, Font.PLAIN, 14"));
- frame3.add(label1);
- frame3.setVisible(true); */
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement