📄 buy.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Buy{
Frame bf=new Frame("购物车窗口");
ActionListener alistener;
ItemListener ilistener;
private Checkbox cb[]=new Checkbox[6];
private Button btn[]=new Button[2];
private Panel p1,p2;
public String str[]=new String[8];
public String st[]=new String[8];
public Font f=new Font("宋体",Font.BOLD,24);
Buy(){
p1=new Panel(new GridLayout(5,2));
cb[0]=new Checkbox("猪肉");
cb[1]=new Checkbox("牛肉");
cb[2]=new Checkbox("羊肉");
cb[3]=new Checkbox("白菜");
cb[4]=new Checkbox("青瓜");
cb[5]=new Checkbox("苹果");
for(int i=0;i<6;i++){
cb[i].addItemListener(ilistener);
}
btn[0]=new Button("提交");
btn[1]=new Button("取消");
for(int j=0;j<2;j++){
btn[j].addActionListener(alistener);
}
for(int i=0;i<=5;i++){
p1.add(cb[i]);
}
for(int i=0;i<2;i++){
p1.add("South",btn[i]);
}
bf.add(p1);
bf.setFont(f);
bf.setResizable(false);
bf.setBackground(Color.magenta);
bf.setForeground(Color.blue);
bf.setSize(250,200);
bf.setLocation(150,100);
bf.setVisible(true);
bf.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
}
});
}
public void itemStateChanged(ItemEvent e){
if(e.getSource()==cb[0])
st[0]=cb[0].getLabel();
if(e.getSource()==cb[1])
st[1]=cb[1].getLabel();
if(e.getSource()==cb[2])
st[2]=cb[2].getLabel();
if(e.getSource()==cb[3])
st[3]=cb[3].getLabel();
if(e.getSource()==cb[4])
st[4]=cb[4].getLabel();
if(e.getSource()==cb[5])
st[5]=cb[5].getLabel();
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn[0]){
str[0]=st[0];
str[1]=st[1];
str[2]=st[2];
str[3]=st[3];
str[4]=st[4];
str[5]=st[5];
DisplayBuy db=new DisplayBuy(str[0],str[1],str[2],str[3],str[4],str[5]);
}
else if(e.getSource()==btn[1]){
for(int j=0;j<6;j++){
cb[j].setState(false);
}
}
}
public static void main(String[] args){
new Buy();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -