📄 searchpro.java
字号:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
/*
* @autor Amadan gong
* @2008.11.17
* @查找产品
*/
public class searchpro implements ActionListener{
JFrame z=null;//类属性
static JTextField tF1=new JTextField();
@SuppressWarnings("deprecation")
public searchpro(JFrame f){ //构造方法,从其调用方法中获得对话框的父窗口
z = new JFrame("search a production"); //产生一modal对话框
Container dialogPane = z.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);
z.setBounds(100,150,500,130);
z.show();
z.pack();
z.setVisible(true);
z.addWindowListener(new WindowAdapter(){//为窗口增加监听器
public void windowClosing(WindowEvent e){//
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
String cmd=e.getActionCommand();
if(cmd.equals("ok")){
try {
int ID=Integer.parseInt(tF1.getText());
new out(z,ID);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if(cmd.equals("no")){
System.exit(0);
}
}
}
class out extends JFrame implements ActionListener{
JFrame fq=null;
public out(JFrame z,int ID)throws IOException{
fq=new JFrame("information");
Container contentPane=fq.getContentPane();
JPanel panel=new JPanel();
JTextArea area=new JTextArea(20,80);
//读取
FileReader fr=new FileReader("production.txt");
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
while(line.indexOf("ID: "+ID)==-1)
{
line=br.readLine();
}
// br.close();
// fr.close();
area.append(line+'\n');
panel.add(area);
contentPane.add(panel,BorderLayout.CENTER);
fq.pack();
fq.setVisible(true);
fq.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent arg0) {
}
}
class MyInput
{
public static String readString()
{
BufferedReader br
=new BufferedReader(new InputStreamReader(System.in),1);
String string=" ";
try
{
string=br.readLine();
}
catch (IOException ex)
{
System.out.println(ex);
}
return string;
}
public static int readInt()
{
return Integer.parseInt(readString());
}
public static float readFloat()
{
return Float.parseFloat(readString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -