把计算器完善完了
This commit is contained in:
@@ -4,7 +4,10 @@ import java.awt.Button;
|
|||||||
import java.awt.Dialog;
|
import java.awt.Dialog;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
import java.awt.Label;
|
import java.awt.Label;
|
||||||
|
import java.awt.Panel;
|
||||||
import java.awt.TextField;
|
import java.awt.TextField;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@@ -24,12 +27,14 @@ public class MyFrame extends Frame {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
setBounds(400, 400, 300, 200);
|
setBounds(400, 400, 300, 200);
|
||||||
TextField num1 = new TextField();
|
TextField num1 = new TextField();
|
||||||
|
Label addKey = new Label("+");
|
||||||
TextField num2 = new TextField();
|
TextField num2 = new TextField();
|
||||||
Button equal2 = new Button("=");
|
Button equal2 = new Button("=");
|
||||||
TextField goal = new TextField();
|
TextField goal = new TextField();
|
||||||
setLayout(new FlowLayout());
|
setLayout(new FlowLayout());
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
add(num1);
|
add(num1);
|
||||||
|
add(addKey);
|
||||||
add(num2);
|
add(num2);
|
||||||
add(equal2);
|
add(equal2);
|
||||||
add(goal);
|
add(goal);
|
||||||
@@ -52,29 +57,43 @@ public class MyFrame extends Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CreateWarning(TextField num1, TextField num2, TextField goal) {
|
public void CreateWarning(TextField num1, TextField num2, TextField goal) {
|
||||||
Dialog warning = new Dialog(this, "please enter a valid number! ");
|
Dialog warning = new Dialog(this, "warning!");
|
||||||
warning.setLayout(new FlowLayout());
|
warning.setLayout(new GridLayout(2, 1));
|
||||||
Button close = new Button("close");
|
warning.setSize(400, 200);
|
||||||
close.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
warning.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
warning.setSize(400, 0);
|
|
||||||
warning.setVisible(true);
|
warning.setVisible(true);
|
||||||
warning.addWindowListener(new WindowAdapter() {
|
warning.addWindowListener(new WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
warning.dispose();
|
warning.dispose();
|
||||||
}
|
|
||||||
});
|
|
||||||
num1.setText("");
|
num1.setText("");
|
||||||
num2.setText("");
|
num2.setText("");
|
||||||
goal.setText("");
|
goal.setText("");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Panel Message = new Panel(new FlowLayout());
|
||||||
|
Panel CloseButton = new Panel(new FlowLayout());
|
||||||
|
|
||||||
|
Button closeButton = new Button("close");
|
||||||
|
Label message = new Label("please enter a valid number!");
|
||||||
|
|
||||||
|
closeButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
warning.dispose();
|
||||||
|
num1.setText("");
|
||||||
|
num2.setText("");
|
||||||
|
goal.setText("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Message.add(message);
|
||||||
|
CloseButton.add(closeButton);
|
||||||
|
warning.add(Message);
|
||||||
|
warning.add(CloseButton);
|
||||||
|
}
|
||||||
|
|
||||||
public String add(double num1, double num2) {
|
public String add(double num1, double num2) {
|
||||||
return String.valueOf(num1 + num2);
|
return String.valueOf(num1 + num2);
|
||||||
|
|||||||
Reference in New Issue
Block a user