做了个计算器
This commit is contained in:
Vendored
+2
-1
@@ -3,5 +3,6 @@
|
|||||||
"java.project.outputPath": "bin",
|
"java.project.outputPath": "bin",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"lib/**/*.jar"
|
"lib/**/*.jar"
|
||||||
]
|
],
|
||||||
|
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: Shutdown.Main
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package Calculator;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new MyFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package Calculator;
|
||||||
|
|
||||||
|
import java.awt.Button;
|
||||||
|
import java.awt.Dialog;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.Label;
|
||||||
|
import java.awt.TextField;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
public class MyFrame extends Frame {
|
||||||
|
public MyFrame() {
|
||||||
|
super("Calculator");
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setVisible(true);
|
||||||
|
setBounds(400, 400, 300, 200);
|
||||||
|
TextField num1 = new TextField();
|
||||||
|
TextField num2 = new TextField();
|
||||||
|
Button equal2 = new Button("=");
|
||||||
|
TextField goal = new TextField();
|
||||||
|
setLayout(new FlowLayout());
|
||||||
|
setResizable(false);
|
||||||
|
add(num1);
|
||||||
|
add(num2);
|
||||||
|
add(equal2);
|
||||||
|
add(goal);
|
||||||
|
equal2.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
goal.setText(add(Double.valueOf(num1.getText()), Double.valueOf(num2.getText())));
|
||||||
|
try {
|
||||||
|
goal.setText(add(Integer.valueOf(num1.getText()), Integer.valueOf(num2.getText())));
|
||||||
|
} catch (java.lang.NumberFormatException event) {
|
||||||
|
// TODO: handle exception
|
||||||
|
}
|
||||||
|
} catch (java.lang.NumberFormatException event) {
|
||||||
|
// TODO: handle exception
|
||||||
|
CreateWarning(num1, num2, goal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateWarning(TextField num1, TextField num2, TextField goal) {
|
||||||
|
Dialog warning = new Dialog(this, "please enter a valid number! ");
|
||||||
|
warning.setLayout(new FlowLayout());
|
||||||
|
Button close = new Button("close");
|
||||||
|
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.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
warning.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
num1.setText("");
|
||||||
|
num2.setText("");
|
||||||
|
goal.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String add(double num1, double num2) {
|
||||||
|
return String.valueOf(num1 + num2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String add(int num1, int num2) {
|
||||||
|
return String.valueOf(num1 + num2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package loginWindow;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class CenterPanel extends Panel {
|
||||||
|
public CenterPanel() {
|
||||||
|
setLayout(new GridLayout(3, 1));
|
||||||
|
TextField UserName = new TextField();
|
||||||
|
TextField Password = new TextField();
|
||||||
|
Button commit = new Button("commit");
|
||||||
|
Password.setEchoChar('*');
|
||||||
|
add(UserName);
|
||||||
|
add(Password);
|
||||||
|
add(commit);
|
||||||
|
commit.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.out.println("Username: \t" + UserName.getText());
|
||||||
|
System.out.println("Password: \t" + Password.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package loginWindow;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new MyFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package loginWindow;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
public class MyFrame extends Frame {
|
||||||
|
public MyFrame() {
|
||||||
|
setVisible(true);
|
||||||
|
setBounds(200, 200, 680, 400);
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
add(new SidePanel((int)(getWidth()*0.2),getHeight()), BorderLayout.WEST);
|
||||||
|
add(new CenterPanel(), BorderLayout.CENTER);
|
||||||
|
add(new SidePanel((int)(getWidth()*0.2),getHeight()), BorderLayout.EAST);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package loginWindow;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SidePanel extends Panel {
|
||||||
|
public SidePanel(int width, int height) {
|
||||||
|
setBackground(new Color(0X39, 0XC5, 0XBB));
|
||||||
|
setSize(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user