📄 updatestoreframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.File;
import java.sql.*;
import java.util.*;
import java.io.*;
class UpdateStoreFrame extends JFrame //库存更新类
{
private JButton findFile;
private JLabel InfoLabel=new JLabel();
String configFile = "";
public UpdateStoreFrame()
{
setTitle("Update PizzaStorage");
setSize(600, 550);
Container contentPane = getContentPane();
JPanel panel = new JPanel();
findFile=new JButton("Open File");
findFile.addActionListener(new FileAction(this));
panel.add(findFile);
contentPane.add(panel, BorderLayout.CENTER);
JPanel ButtonPanel = new JPanel();
JButton okButton = new JButton("Sure");
okButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
updateInfo();
setVisible(false);
}
catch(SQLException b)
{
b.printStackTrace();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
});
ButtonPanel.add(okButton);
contentPane.add(ButtonPanel, BorderLayout.SOUTH);
JButton closeButton = new JButton("Close");
closeButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setVisible(false);
}
});
ButtonPanel.add(closeButton);
contentPane.add(ButtonPanel, BorderLayout.SOUTH);
setSize(200, 200);
}
private void updateInfo() throws FileNotFoundException,IOException,SQLException
{
BufferedReader in=new BufferedReader(new FileReader(configFile));
String line;
while((line=in.readLine())!=null)
{
if(line.length()<1)
continue;
StringTokenizer t=new StringTokenizer(line," ");
String pizzaType=t.nextToken();
int baseType=Integer.parseInt(t.nextToken());
int size=Integer.parseInt(t.nextToken());
int quantity=Integer.parseInt(t.nextToken());
Connect.getConnection();
Connect.updatestore(pizzaType,baseType,size,quantity);
}
}
private String openFile(JFrame frame)
{
String s = null;
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(new PizzaFilter());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (chooser.showOpenDialog(frame) ==
JFileChooser.APPROVE_OPTION) {
s = chooser.getSelectedFile().toString();
}
return s;
}
class FileAction extends AbstractAction
{
public FileAction(JFrame frame)
{
super("fileOpenCommand");
this.frame = frame;
}
public void actionPerformed(ActionEvent e)
{
String s = openFile(frame);
if (s != null) {
configFile = s;
}
}
private JFrame frame;
}
}
//只接受HTML, Java, 或text file.
class PizzaFilter extends javax.swing.filechooser.FileFilter
{
static String[] extensions = {
".txt",
".java",
".html",
};
public boolean accept(File f)
{
if (f.isDirectory())
return true;
for (int i=0; i<extensions.length; i++)
if (f.getName().toLowerCase().endsWith(extensions[i]))
return true;
return false;
}
public String getDescription()
{
return "Pizza Store file";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -