work on class 05/05

This commit is contained in:
2022-05-05 16:12:28 +02:00
parent 9a97e6dfbd
commit 608c59d3e3
16 changed files with 183 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package GUI;
import javax.swing.*;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
@ -10,9 +9,7 @@ import java.awt.event.ActionListener;
public class GUI1 extends JFrame {
public static void main(String[] args) {
GUI1 f1 = new GUI1();
new GUI1();
}
GUI1(){

View File

@ -1,10 +1,80 @@
package GUI;
public class GUI2 {
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.Container;
/**
*
*/
public class GUI2 extends JFrame{
int number;
public static void main(String[] args) {
new GUI2();
}
/**
*
*/
GUI2(){
setSize(200,200);
setLocation(600,200);
Container c = this.getContentPane();
BoxLayout fl = new BoxLayout(c, BoxLayout.Y_AXIS);
c.setLayout(fl);
JSlider js1 = new JSlider(0, 100);
js1.setValue(0);
JProgressBar jp1 = new JProgressBar(0, 100);
JLabel jl1 = new JLabel("waiting");
Listener l = new Listener(jp1, jl1, js1);
js1.addChangeListener(l);
c.add(js1);
c.add(jp1);
c.add(jl1);
this.setVisible(true);
}
}
/**
*
*/
class Listener implements ChangeListener {
JProgressBar jp1;
JLabel jl1;
JSlider js1;
int number = 0;
/**
*
* @param jp1
* @param jl1
* @param js1
*/
Listener(JProgressBar jp1, JLabel jl1, JSlider js1){
this.jp1 = jp1;
this.jl1 = jl1;
this.js1 = js1;
}
/**
*
* @param e
*/
@Override
public void stateChanged(ChangeEvent e) {
number = js1.getValue();
jl1.setText("" + number);
jp1.setValue(number);
}
}