This commit is contained in:
2022-05-05 14:40:19 +02:00
parent b8951031cd
commit 9a97e6dfbd
7 changed files with 87 additions and 2 deletions

64
src/GUI/GUI1.java Normal file
View File

@ -0,0 +1,64 @@
package GUI;
import javax.swing.*;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI1 extends JFrame {
public static void main(String[] args) {
GUI1 f1 = new GUI1();
}
GUI1(){
setTitle("Me");
setSize(200,200);
setLocation(600,200);
FlowLayout fl = new FlowLayout();
this.setLayout(fl);
this.getContentPane().setBackground(Color.GREEN);
JButton jb1 = new JButton("Foo");
JButton jb2 = new JButton("bar");
ButtonListener bl = new ButtonListener(this);
jb1.addActionListener(bl);
jb2.addActionListener(bl);
this.add(jb1);
this.add(jb2);
this.setVisible(true);
}
}
class ButtonListener implements ActionListener{
JFrame f1;
ButtonListener(JFrame f1){
this.f1 = f1;
}
//change color from background
@Override
public void actionPerformed(ActionEvent e){
if(f1.getContentPane().getBackground()==Color.GREEN) {
f1.getContentPane().setBackground(Color.BLUE);
}
else {
f1.getContentPane().setBackground(Color.GREEN);
}
if (e.getActionCommand().contains("bar")) {
f1.getContentPane().setBackground(Color.ORANGE);
}
}
}

10
src/GUI/GUI2.java Normal file
View File

@ -0,0 +1,10 @@
package GUI;
public class GUI2 {
public static void main(String[] args) {
}
}