Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JButton;
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import javax.swing.JPanel;
  6.  
  7. import javax.swing.border.Border;
  8. import javax.swing.border.LineBorder;
  9.  
  10. public class buttonProblem extends JFrame
  11. {
  12.     public buttonProblem()
  13.     {  
  14.    
  15.     //Could not get this to work
  16.     /*
  17.     private static boolean USE_CROSS_PLATFORM_UI = false;
  18.    
  19.     int buttonLabelIndex = 0;
  20.    
  21.     String button1Labels[] = { "COLOR", "COLOR",  "COLOR", "COLOR", "COLOR"};
  22.     Color  button1Colors[] = { Color.BLUE,  Color.GREEN, Color.ORANGE, Color.PINK, Color.YELLOW};
  23.     JButton button1;
  24.    
  25.     String button2Labels[] = { "COLOR", "COLOR",  "COLOR", "COLOR", "COLOR"};
  26.     Color  button2Colors[] = { Color.BLUE,  Color.GREEN, Color.ORANGE, Color.PINK, Color.YELLOW};
  27.     JButton button2;
  28.     */
  29.    
  30.         setTitle("buttonProblem");
  31.  
  32.         setLayout(null);
  33.            
  34.             //Set up JPanel
  35.             JPanel panel = new JPanel();
  36.             panel.setLayout(new BorderLayout());
  37.            
  38.             //Set up Border
  39.             Border thickBorder = new LineBorder(Color.WHITE, 150);
  40.            
  41.             //Create button1
  42.             JButton button1 = new JButton("Button 1");
  43.             panel.add(button1, BorderLayout.CENTER);
  44.            
  45.             //set button size
  46.             button1.setBounds(100, 125, 200, 150);
  47.            
  48.             //set button color
  49.             button1.setOpaque(true);
  50.            
  51.             //create button2
  52.             JButton button2 = new JButton("Button 2");
  53.             panel.add(button2, BorderLayout.CENTER);
  54.            
  55.             //set button size
  56.             button2.setBounds(300, 125, 200, 150);
  57.            
  58.             //set button color
  59.             button2.setOpaque(true);
  60.  
  61.             add(button1);
  62.             add(button2);
  63.  
  64.             //set default window size
  65.             setSize(600, 450);
  66.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67.             setLocationRelativeTo(null);
  68.             setVisible(true);
  69.            
  70. //Could not get this to work
  71. /*     
  72.     public void actionPerformed(ActionEvent e)
  73.     {
  74.         buttonLabelIndex = ++buttonLabelIndex < button1Labels.length?buttonLabelIndex:0;
  75.         buttonLabelIndex = ++buttonLabelIndex < button2Labels.length?buttonLabelIndex:0;
  76.  
  77.         button1.setText(button1Labels[buttonLabelIndex]);
  78.         button2.setText(button1Labels[buttonLabelIndex]);
  79.        
  80.         if(USE_CROSS_PLATFORM_UI)
  81.         {
  82.             button1.setBackground(button1Colors[buttonLabelIndex]);
  83.             button2.setBackground(button2Colors[buttonLabelIndex]);
  84.         }
  85.         else
  86.         {
  87.             button1.setForeground(button2Colors[buttonLabelIndex]);
  88.             button2.setForeground(button1Colors[buttonLabelIndex]);
  89.         }
  90.     }
  91. */
  92.                    
  93.     }
  94.  
  95.     public static void main(String[] args)
  96.     {
  97.         new buttonProblem();
  98.     }
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement