шпаргалки
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
1.8 KiB

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author (C)Y.D.Zakovryashin, 28.11.2022
*/
public class DemoJFrame extends JFrame {
private JLabel lbl;
public DemoJFrame(String title) {
super(title);
// setBounds (x, y, w, h);
// setTitle (title);
setLocation(120, 80);
setSize(640, 480);
setResizable(false);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
init();
setVisible(true);
}
public static void main(String[] args) {
DemoJFrame demo = new DemoJFrame("Demo JFrame");
}
private void init() {
// DemoWindowListener wl = new DemoWindowListener();
// addWindowListener(wl);
addWindowListener(new DemoWindowAdapter());
Container cp = getContentPane();
cp.setLayout(null);
// cp.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));
lbl = new JLabel("Demo label");
lbl.setBounds(120, 80, 160, 32);
JButton b = new JButton("Demo button");
b.setBounds(120, 140, 160, 32);
b.addActionListener(new DemoActionListener(cp));
// class ? implements ActionListener { .... }
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s = lbl.getText();
lbl.setText(s + "*");
}
});
cp.add(lbl);
cp.add(b);
}
}