-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain02.java
More file actions
36 lines (31 loc) · 964 Bytes
/
Copy pathMain02.java
File metadata and controls
36 lines (31 loc) · 964 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
34
35
36
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main02{
public static void main(String args[]){
new AppFrame();
}
}
class AppFrame extends JFrame{
JTextField in = new JTextField();
JButton btn = new JButton("evaluate x square");
JLabel out = new JLabel("label for showing the result");
public AppFrame(){
setLayout(new FlowLayout());
getContentPane().add(in);
getContentPane().add(btn);
getContentPane().add(out);
btn.addActionListener(new BtnActionAdapter());
// btn.setSize(200, 50);
setSize(400,100);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
class BtnActionAdapter implements ActionListener{
public void actionPerformed(ActionEvent e){
String s = in.getText();
double d = Double.parseDouble(s);
out.setText("square is: " + d*d);
}
}
}