📄 invcheckspec.java
字号:
package user_interface;
import engine.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Calendar;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import integrate.*;
public class InvCheckSpec extends JFrame{
private JFrame parentWin;
public JToggleButton jbbb=null;
private Structure inputStructure;
private Structure greedyOutput;
public InvCheckSpec(){
super("Designated Check");
setSize(Constant.frameWidth, Constant.frameHeight);
//set the background
((JPanel)this.getContentPane()).setOpaque(false);
ImageIcon img = new ImageIcon("BG.jpg");
JLabel background = new JLabel(img);
this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(),img.getIconHeight());
setVisible(true);
addButtons();
repaint();
}
public void paint(Graphics g) {
super.paint(g);
//g.setColor(Color.gray);
}
public void addButtons() {
parentWin=this;
// Button Start
jbbb=new JToggleButton();
jbbb.setText("Start");
jbbb.setBounds(new Rectangle(Constant.frameWidth/2-Constant.boxWidth/2, Constant.frameHeight/2+Constant.boxHeight/2+Constant.buttonClearance, Constant.boxWidth,
Constant.boxHeight));
jbbb.setToolTipText("Start inventory check");
jbbb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
// Greedy greedyInput=new Greedy(inputStructure);
Calendar a = Calendar.getInstance();
parentWin.remove(jbbb);
repaint();
Test test=new Test(inputStructure);
System.out.println("draw");
Calendar b = Calendar.getInstance();
System.out.println("Time");
System.out.println(a.get(Calendar.HOUR)
+":"+a.get(Calendar.MINUTE)
+":"+a.get(Calendar.SECOND));
System.out.println(b.get(Calendar.HOUR)
+":"+b.get(Calendar.MINUTE)
+":"+b.get(Calendar.SECOND));
Resolution result=new Resolution(test.finalOutput);
DBinput db=new DBinput();
int res=db.invCheck(test.finalOutput);
if (res==-1){
Error err=new Error("Connect to database fail!");
}
}}
);
//Button Browse
final JLabel label = new JLabel();
JToggleButton jb=new JToggleButton();
jb.setText("Browse");
jb.setBounds(new Rectangle(Constant.frameWidth/2-Constant.boxWidth/2, Constant.frameHeight/2-Constant.boxHeight/2, Constant.boxWidth,
Constant.boxHeight));
jb.setToolTipText("Designate an input file.");
this.getContentPane().add(jb);
this.getContentPane().add(label);
jb.setVisible(true);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
FileDialog fd=new FileDialog(parentWin,"Open file");
fd.setVisible(true);
try{
String filename=fd.getFile();
String fileDic=fd.getDirectory();
//FileInputStream fis=new FileInputStream( fd.getDirectory()+fd.getFile());
inputStructure=readFromFile(fileDic+filename);
if (inputStructure==null){
Error err=new Error("Invalid Input!");
}else{
parentWin.getContentPane().add(jbbb);
jbbb.setVisible(true);
repaint();
}
}catch(Exception e){
System.out.println();
Error err=new Error("Invalid Input!");
}
}}
);
//Button Back
JToggleButton jbb=new JToggleButton();
jbb.setText("Back");
jbb.setBounds(new Rectangle(Constant.frameWidth/2-Constant.boxWidth/2, Constant.frameHeight/2+2*Constant.buttonClearance+Constant.boxHeight/2*3, Constant.boxWidth,
Constant.boxHeight));
jbb.setToolTipText("Back.");
this.getContentPane().add(jbb);
jbb.setVisible(true);
jbb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
parentWin.dispose();
}}
);
}
public Structure readFromFile(String fileN){
int i,j=0, n=0;
int layerID=1, rankID=0;
try{
BufferedReader in = new BufferedReader(new FileReader(fileN));
String balance;
Structure input=new Structure(50);
do{
balance=in.readLine();
if (balance!=null){
n++;
for (i=0; i<balance.length();i++){
if (balance.charAt(i)==','){
j=i;
}
}
if (j==0){
System.out.println("Invalid Input file!");
}
String layer=balance.substring(0, j);
String rank=balance.substring(j+1, balance.length());
layerID = Integer.valueOf(layer.trim()).intValue();
rankID = Integer.valueOf(rank.trim()).intValue();
input.unitList[n]=new Coor();
input.unitList[n].layer=layerID;
input.unitList[n].rank=rankID;
if (input.unitList[n].isValid()==0)
return null;
}
} while (balance!=null);
input.unitList[0]=new Coor();
input.unitList[n+1]=new Coor();
input.unitNum=n+1;
in.close();
return input;
}
catch(IOException ioe){
System.out.println("Problem reading ");
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -