?? girdlayout.java
字號:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
public class Girdlayout extends JFrame{
Label t,x1,x2;
double result,h;
Button b1,b2,b3,b4,b5;
Button b11,b22,b33,b44,b55;
Button y1;
TextField txt1,txt2,txt3,txt4;
Saving m1;
Withdraw m2;
Search m3;
Changmima m4;
String a,b;
Frame d;
public Girdlayout(){
result=0.0;
m1=new Saving();
m2=new Withdraw();
m3=new Search();
m4=new Changmima();
setSize(300,300);
setTitle("登錄成功");
GridBagLayout gridbag=new GridBagLayout();
setLayout(gridbag);
GridBagConstraints c=new GridBagConstraints();
c.fill=GridBagConstraints.BOTH;
c.weighty=0.5;
t=new Label("請選擇你要進行的操作:",Label.CENTER);
c.gridwidth=GridBagConstraints.REMAINDER;
gridbag.setConstraints(t,c);
add(t);
c.weightx=0.5;
c.weighty=0;
c.gridwidth=2;
b1=new Button("存款");
gridbag.setConstraints(b1,c);
a=new String();
txt1=new TextField(8);
txt1.setBounds(new Rectangle(115,59,180,33));
m1.add(txt1);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b11=new Button("確定");
b11.setBounds(new Rectangle(78,220,86,30));
b11.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a=txt1.getText();
result+=Double.parseDouble(a);
txt1.setText("");
m1.dispose(); }});
m1.add(b11);
b22=new Button("取消");
b22.setBounds(new Rectangle(193,220,86,30));
b22.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText("");}});
m1.add(b22);
m1.show();
}});
add(b1);
d=new Frame();
d.setSize(400,300);
d.setTitle("取款失敗");
y1=new Button("確定");
y1.setBounds(new Rectangle(78,220,86,30));
x1=new Label("你的取款額大于你的余款額!");
x1.setBounds(new Rectangle(45,58,167,33));
x2=new Label("你的余款額:");
x2.setBounds(new Rectangle(45,105,167,33));
d.setLayout(null);
txt4=new TextField(8);
txt4.setEditable(false);
txt4.setBounds(new Rectangle(45,150,180,33));
y1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
d.dispose();}});
d.add(y1);
d.add(x1);
d.add(x2);
d.add(txt4);
c.gridheight=2;
b2=new Button("取款");
gridbag.setConstraints(b2,c);
txt2=new TextField(8);
txt2.setBounds(new Rectangle(115,59,180,33));
m2.add(txt2);
b=new String();
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b44=new Button("確定");
b44.setBounds(new Rectangle(78,220,86,30));
b44.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b=txt2.getText();
h=Double.parseDouble(b);
if(h<=result){
txt2.setText("");
result=result-h;
m2.dispose();}
else{txt2.setText("");txt4.setText(""+result);d.show();
m2.dispose();}
}});
m2.add(b44);
b55=new Button("取消");
b55.setBounds(new Rectangle(193,220,86,30));
b55.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt2.setText("");}});
m2.add(b55);
m2.show();}});
add(b2);
c.gridheight=3;
b3=new Button("查詢余額");
gridbag.setConstraints(b3,c);
txt3=new TextField();
txt3.setEditable(false);
txt3.setBounds(new Rectangle(115,59,180,33));
m3.add(txt3);
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt3.setText(""+result);
b33=new Button("退出");
b33.setBounds(new Rectangle(78,220,86,30));
b33.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
m3.dispose();}});
m3.add(b33);
m3.show();}});
add(b3);
c.gridheight=4;
b4=new Button("修改密碼");
gridbag.setConstraints(b4,c);
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
m4.show();}});
add(b4);
c.gridwidth=GridBagConstraints.REMAINDER;
b5=new Button("退出");
gridbag.setConstraints(b5,c);
b5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();}});
add(b5);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -