Guest User

Untitled

a guest
Jan 12th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. Container contentPane = getContentPane();
  2.         contentPane.setLayout(new FlowLayout());
  3.        
  4.         redButton = new JButton("RED");
  5.         redButton.setForeground(Color.RED);
  6.         contentPane.add(redButton);
  7.         redButton.addActionListener(this);
  8.  
  9.     private void changeRedColor()
  10.     {
  11.         Container contentPane = getContentPane();
  12.         contentPane.setBackground(Color.RED);
  13.     }
  14.  
  15. //Vill att dessa två events triggas när den röda knappen klickas, hur gör jag?
  16.  
  17.     public void actionPerformed(ActionEvent event) {
  18.         JButton clickedButton = (JButton) event.getSource();
  19.  
  20.         String  buttonText = clickedButton.getText();
  21.  
  22.         this.setTitle("You clicked " + buttonText);
  23.     }
  24.    
  25.    
  26.     public void actionPerformed(ActionEvent event) {
  27.         changeRedColor();
  28.     }
Add Comment
Please, Sign In to add comment