Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import javax.swing.JPanel;
- import javax.swing.border.Border;
- import javax.swing.border.LineBorder;
- public class buttonProblem extends JFrame
- {
- public buttonProblem()
- {
- //Could not get this to work
- /*
- private static boolean USE_CROSS_PLATFORM_UI = false;
- int buttonLabelIndex = 0;
- String button1Labels[] = { "COLOR", "COLOR", "COLOR", "COLOR", "COLOR"};
- Color button1Colors[] = { Color.BLUE, Color.GREEN, Color.ORANGE, Color.PINK, Color.YELLOW};
- JButton button1;
- String button2Labels[] = { "COLOR", "COLOR", "COLOR", "COLOR", "COLOR"};
- Color button2Colors[] = { Color.BLUE, Color.GREEN, Color.ORANGE, Color.PINK, Color.YELLOW};
- JButton button2;
- */
- setTitle("buttonProblem");
- setLayout(null);
- //Set up JPanel
- JPanel panel = new JPanel();
- panel.setLayout(new BorderLayout());
- //Set up Border
- Border thickBorder = new LineBorder(Color.WHITE, 150);
- //Create button1
- JButton button1 = new JButton("Button 1");
- panel.add(button1, BorderLayout.CENTER);
- //set button size
- button1.setBounds(100, 125, 200, 150);
- //set button color
- button1.setOpaque(true);
- //create button2
- JButton button2 = new JButton("Button 2");
- panel.add(button2, BorderLayout.CENTER);
- //set button size
- button2.setBounds(300, 125, 200, 150);
- //set button color
- button2.setOpaque(true);
- add(button1);
- add(button2);
- //set default window size
- setSize(600, 450);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLocationRelativeTo(null);
- setVisible(true);
- //Could not get this to work
- /*
- public void actionPerformed(ActionEvent e)
- {
- buttonLabelIndex = ++buttonLabelIndex < button1Labels.length?buttonLabelIndex:0;
- buttonLabelIndex = ++buttonLabelIndex < button2Labels.length?buttonLabelIndex:0;
- button1.setText(button1Labels[buttonLabelIndex]);
- button2.setText(button1Labels[buttonLabelIndex]);
- if(USE_CROSS_PLATFORM_UI)
- {
- button1.setBackground(button1Colors[buttonLabelIndex]);
- button2.setBackground(button2Colors[buttonLabelIndex]);
- }
- else
- {
- button1.setForeground(button2Colors[buttonLabelIndex]);
- button2.setForeground(button1Colors[buttonLabelIndex]);
- }
- }
- */
- }
- public static void main(String[] args)
- {
- new buttonProblem();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement