📄 remove.java
字号:
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
class remove implements ActionListener{
JDialog dialog;
JTextField tF1=new JTextField();
remove(JFrame f){ //构造方法,从其调用方法中获得对话框的父窗口
dialog = new JDialog(f,"remove a production",true); //产生一modal对话框
Container dialogPane = dialog.getContentPane();//接下来注意添加各个组件
dialogPane.setLayout(new GridLayout(2,2));
dialogPane.add(new JLabel("please input the production's ID : ",SwingConstants.CENTER));
dialogPane.add(tF1);
JButton b1 = new JButton("ok");
dialogPane.add(b1);
JButton b2 = new JButton("no");
dialogPane.add(b2);
b1.addActionListener(this); //为两按钮增加事件监听器
b2.addActionListener(this);
dialog.setBounds(100,150,600,130);
dialog.show();
}
public void actionPerformed(ActionEvent e){
String cmd=e.getActionCommand();
if(cmd.equals("ok")){
try{
int ID=Integer.parseInt(tF1.getText());
FileReader fr=new FileReader("production.txt");
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
int i=1;
do{
i++;
line=br.readLine();
}while(line.indexOf("ID: "+ID)!=-1);
}
catch(Exception ex){
System.out.println("can't finish your order");
}
}
else if(cmd.equals("no")){
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -