From c179256b8057055466dff7e50c07e31678a82d8f Mon Sep 17 00:00:00 2001 From: msksbr Date: Sat, 22 Jun 2024 21:56:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E8=AE=A1=E7=AE=97=E5=99=A8=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/GUItest/src/Calculator/MyFrame.java | 47 +++++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/test/GUItest/src/Calculator/MyFrame.java b/test/GUItest/src/Calculator/MyFrame.java index fed6419..b556693 100644 --- a/test/GUItest/src/Calculator/MyFrame.java +++ b/test/GUItest/src/Calculator/MyFrame.java @@ -4,7 +4,10 @@ import java.awt.Button; import java.awt.Dialog; import java.awt.FlowLayout; import java.awt.Frame; +import java.awt.GridBagLayout; +import java.awt.GridLayout; import java.awt.Label; +import java.awt.Panel; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -24,12 +27,14 @@ public class MyFrame extends Frame { setVisible(true); setBounds(400, 400, 300, 200); TextField num1 = new TextField(); + Label addKey = new Label("+"); TextField num2 = new TextField(); Button equal2 = new Button("="); TextField goal = new TextField(); setLayout(new FlowLayout()); setResizable(false); add(num1); + add(addKey); add(num2); add(equal2); add(goal); @@ -52,28 +57,42 @@ public class MyFrame extends Frame { } 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); + Dialog warning = new Dialog(this, "warning!"); + warning.setLayout(new GridLayout(2, 1)); + warning.setSize(400, 200); 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(""); } }); - num1.setText(""); - num2.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) {