-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
33 lines (31 loc) · 918 Bytes
/
Button.java
File metadata and controls
33 lines (31 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import javax.swing.*;
import java.awt.event.*;
public class Main{
public static void main(String[] args) {
new MyFrame();
}
}
class MyFrame extends JFrame implements ActionListener{
JButton button;
MyFrame()
{
button=new JButton();
button.setBounds(90,150, 200, 50);
button.addActionListener(this);
button.setText("Yamete, Press Me!");
button.setHorizontalAlignment(JButton.CENTER);
button.setVerticalAlignment(JButton.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Just a FRAME");
this.setSize(400,400);
this.setVisible(true);
this.setLayout(null);
this.add(button);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{System.out.println("I'm pressed!!");}
}
}