📄 littleapp.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LittleAPP extends Applet implements ActionListener
{
Label 货号,名称,数量,计量单位,单价单位,单价金额,合计金额,日期,小计;
TextField text[]=new TextField[22];
Choice choice[]=new Choice[8];
Button b1,b2;
int x=0,y=0,w,h;
public void init()
{
setLayout(new BorderLayout());
ScrollPane scroll_p=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p2=new Panel();p2.setLayout(null);
p2.setSize(550,180);
货号=new Label( "货号:",Label.CENTER);
名称=new Label("名称:",Label.CENTER);
数量=new Label("数量",Label.CENTER);
计量单位=new Label("计量单位:",Label.CENTER);
单价单位=new Label("单价单位:",Label.CENTER);
单价金额=new Label("单价金额:",Label.CENTER);
合计金额=new Label("合计金额:",Label.CENTER);
日期=new Label("日期:",Label.CENTER);
小计=new Label("小计:",Label.CENTER);
for(int i=0;i<=21;i++)
{
text[i]=new TextField("0");
}
for(int i=0;i<=7;i++)
{
choice[i]=new Choice();
if(i<=3)
{
choice[i].add("个");choice[i].add("台");
choice[i].add("辆"); choice[i].add("箱");
}
else
{
choice[i].add("万元"); choice[i].add("千元");
choice[i].add("百元"); choice[i].add("元");
}
}
w=p2.getSize().width;
h=p2.getSize().height;//获取面板的宽和高
x=w/9;y=h/6;
p2.add(货号);p2.add(名称);
p2.add(数量);p2.add(计量单位);
p2.add(单价单位);p2.add(单价金额);
p2.add(合计金额);p2.add(日期);
p2.add(小计);
for(int i=0;i<=21;i++)
{
p2.add(text[i]);
}
for(int i=0;i<=7;i++)
{
p2.add(choice[i]);
}
货号.setBounds(0,0,x,y); //货号及下面的文本框
text[0].setBounds(0,y,x,y);text[1].setBounds(0,2*y,x,y);
text[2].setBounds(0,3*y,x,y);text[3].setBounds(0,4*y,x,y);
名称.setBounds(x,0,x+x/2,y); //名称及下面的文本框:
text[4].setBounds(x,y,2*x,y);text[5].setBounds(x,2*y,2*x,y);
text[6].setBounds(x,3*y,2*x,y);text[7].setBounds(x,4*y,2*x,y);
数量.setBounds (3*x,0,x,y);//数量单位及下面的文本框:
text[8].setBounds(3*x,y,x,y);text[9].setBounds(3*x,2*y,x,y);
text[10].setBounds(3*x,3*y,x,y);text[11].setBounds(3*x,4*y,x,y);
计量单位.setBounds (4*x,0,x,y);//计量单位及下面的文本框:
choice[0].setBounds(4*x,y,x,y);choice[1].setBounds(4*x,2*y,x,y);
choice[2].setBounds(4*x,3*y,x,y);choice[3].setBounds(4*x,4*y,x,y);
单价单位.setBounds (5*x,0,x,y);//单价单位及下面的文本框:
choice[4].setBounds(5*x,y,x,y);choice[5].setBounds(5*x,2*y,x,y);
choice[6].setBounds(5*x,3*y,x,y);choice[7].setBounds(5*x,4*y,x,y);
单价金额.setBounds (6*x,0,x,y);//单价金额及下面的文本框:
text[12].setBounds(6*x,y,x,y);text[13].setBounds(6*x,2*y,x,y);
text[14].setBounds(6*x,3*y,x,y);text[15].setBounds(6*x,4*y,x,y);
合计金额.setBounds (7*x,0,x,y); //合计金额及下面的文本框:
text[18].setBounds(7*x,y,2*x,y);text[19].setBounds(7*x,2*y,2*x,y);
text[20].setBounds(7*x,3*y,2*x,y);text[21].setBounds(7*x,4*y,2*x,y);
小计.setBounds (0,5*y,x,y);//小计及下面的文本框:
text[16].setBounds(x,5*y,4*x,y);
text[16].setEditable(false);
text[16].setBackground(Color.pink);
日期.setBounds(5*x,5*y,x,y);//日期及下面的文本框:
text[17].setBounds(6*x,5*y,3*x,y);
text[17].setEditable(false);
text[17].setBackground(Color.cyan);
Panel p=new Panel();//用来添加按钮的面板
b1=new Button("确定");
b2=new Button("取消");
p.add(b1);
p.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
add(p,"South");
add(new Label("销售货物单",Label.CENTER),"North");
scroll_p.add(p2);//滚动窗体添加面板p2
add(scroll_p,"Center");//滚动窗体添加到中心
}
public void actionPerformed(ActionEvent e)//处理按钮事件
{
double number=0,sum=0;
if(e.getSource()==b1)
{
for(int i=8;i<=11;i++)
{
if(text[i].getText()!=null)
{
double number1=Double.valueOf(text[i].getText()).doubleValue();
double number2=Double.valueOf(text[i+4].getText()).doubleValue();
number=number1*number2;
}
else
{
number=0.0;
}
text[i+10].setText(number+choice[i-4].getSelectedItem());
if(choice[i-4].getSelectedItem().equals("万元"))
{
sum=sum+number*10000;
}
else if(choice[i-4].getSelectedItem().equals("千元"))
{
sum=sum+number*1000;
}
else if(choice[i-4].getSelectedItem().equals("百元"))
{
sum=sum+number*100;
}
else if(choice[i-4].getSelectedItem().equals("元"))
{
sum=sum+number;
}
}
text[16].setText("人民币:"+sum+"元");
text[17].setText(new java.util.Date().toString());
}
else if(e.getSource()==b2)
{
for(int i=0;i<=21;i++)
{
text[i].setText("0");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -