📄 a045a2c78c5200191ca78beaf407f73b
字号:
/* 主界面的窗口 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class MainFrame implements ActionListener {
GeneralFrame mainFrame;
MenuBar mainMenuBar;
Menu fileMenu, helpMenu;
JTable mainJTable;
MenuItem searchMenuItem, inputMenuItem, warnMenuItem, exitMenuItem,aboutMenuItem;
TextField payText, costText, giveText,idText,numText;
Label payLabel, costLabel, giveLabel,idLabel,numLabel;
Label jice,timeLabel;
Panel firstPanel_1, firstPanel_2,firstPanel_3;
Panel twoPanel_1,twoPanel_2;
Button okButton,cancelButton,computeButton;
Object mainData[][];
Date nowDate;
int n=0;
public MainFrame() {
mainFrame = new GeneralFrame("音像管理系统");
mainFrame.setSize(800,480);
mainFrame.setResizable(false);
/* 变量定义 */
/**********************************/
mainMenuBar = new MenuBar();
mainFrame.setMenuBar(mainMenuBar);
fileMenu = new Menu("文件");
helpMenu = new Menu("帮助");
firstPanel_1 = new Panel();
firstPanel_2 = new Panel();
firstPanel_1.setBackground(Color.gray);
//firstPanel_2.setBackground(Color.green);
firstPanel_3=new Panel();
twoPanel_1=new Panel();
twoPanel_2=new Panel();
mainData = new Object[13][6];
String mainName[] = { "编号", "类型", "歌手", "专辑名", "单价", "日期" };
mainJTable = new JTable(mainData, mainName);
JScrollPane p = new JScrollPane(mainJTable);
mainFrame.setLayout(new GridLayout(2,1));
mainFrame.add(p);
mainFrame.add(firstPanel_3);
//mainFrame.add(firstPanel_2);
firstPanel_3.setLayout(new GridLayout(2,1));
firstPanel_3.add(firstPanel_1);
firstPanel_3.add(firstPanel_2);
firstPanel_1.setLayout(new GridLayout(2,1));
firstPanel_1.add(twoPanel_1);
firstPanel_1.add(twoPanel_2);
searchMenuItem = new MenuItem("查找");
inputMenuItem = new MenuItem("入货");
warnMenuItem = new MenuItem("提示");
exitMenuItem = new MenuItem("退出");
aboutMenuItem=new MenuItem("关于");
payText = new TextField(18);
costText = new TextField(18);
giveText = new TextField(18);
idText=new TextField(18);
numText=new TextField("1",18);
payLabel = new Label("顾客付款");
costLabel = new Label("应付款数");
giveLabel = new Label("找零数");
idLabel=new Label("输入编号");
numLabel=new Label("购买数量");
jice=new Label("403工作室 樊鹏飞 张毅飞 杨亮亮");
timeLabel=new Label();
nowDate=new Date();
timeLabel.setText("当前时间 "+new Date(nowDate.getTime()));
jice.setBackground(Color.green);
okButton=new Button(" 确定 ");
cancelButton=new Button(" 取消 ");
computeButton=new Button(" 计算 ");
//for(int i=0;i<20;i++)
//System.out.print(new Date(nowDate.getTime()));
//payLabel.setBounds(200,440,60,40);
mainMenuBar.add(fileMenu);
mainMenuBar.add(helpMenu);
//mainFrame.pack();
fileMenu.add(searchMenuItem);
fileMenu.add(inputMenuItem);
fileMenu.add(warnMenuItem);
fileMenu.add(exitMenuItem);
helpMenu.add(aboutMenuItem); //增加了菜单等组件
twoPanel_1.setLayout(new FlowLayout(FlowLayout.LEFT));
twoPanel_1.add(idLabel);
twoPanel_1.add(idText);
twoPanel_1.add(numLabel);
twoPanel_1.add(numText);
twoPanel_1.add(okButton);
twoPanel_1.add(cancelButton);
twoPanel_2.setLayout(new FlowLayout(FlowLayout.LEFT));
twoPanel_2.add(payLabel);
twoPanel_2.add(payText);
twoPanel_2.add(costLabel);
twoPanel_2.add(costText);
twoPanel_2.add(giveLabel);
twoPanel_2.add(giveText);
twoPanel_2.add(computeButton);
firstPanel_2.setLayout(new BorderLayout());
firstPanel_2.add(jice,BorderLayout.SOUTH);
firstPanel_2.add(timeLabel,BorderLayout.NORTH);
mainFrame.show();
searchMenuItem.addActionListener(this);
inputMenuItem.addActionListener(this);
exitMenuItem.addActionListener(this);
aboutMenuItem.addActionListener(this);
okButton.addActionListener(this);
}
/* **************** 一些事件方法 ******************** */
public void okButtonMarkNum(){ //标记点击确定按钮的次数
n++;
}
public void okButtonAction(){
Music one=new Music();
DataIO oneGoods=new DataIO();
oneGoods.dataInput(this.idText.getText());
for(int i=0;i<=n;i++){
this.mainData[i][0]=oneGoods.inputMusic.musicID;
this.mainData[i][1]=oneGoods.inputMusic.musicType;
this.mainData[i][2]=oneGoods.inputMusic.singer;
this.mainData[i][3]=oneGoods.inputMusic.recordName;
this.mainData[i][4]=oneGoods.inputMusic.price;
this.mainData[i][5]=oneGoods.inputMusic.date;
}
this.idText.setText("");
}
public void actionPerformed(ActionEvent event) { //菜单事件处理
String eventName;
eventName = event.getActionCommand();
if (eventName.equals("退出")) {
System.exit(0);
} else if (eventName.equals("查找")) {
new SearchFrame().showSearchFrame();
} else if (eventName.equals("入货")) {
new InputGoods().showInputFrame();
}
else if(eventName.equals("关于")){
new AboutSystem().showAboutFrame();
}
else if(eventName.equals(" 确定 ")){
this.okButtonAction();
this.okButtonMarkNum();
}
}
/* 各种方法的实现 */
}
//public class Test {
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -