首页 新闻 会员 周边 捐助

组件不显示,为啥呀

0
[待解决问题]

package 界面层;
import java.util.List;
import java.util.ArrayList;
import java.awt.;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.awt.event.
;

import javax.swing.*;
public class selectPanel extends JPanel{
private JButton button0,button1,button2;
private List<thing2>things;
private JLabel label;
private JTextField field;
JPanel panel2=new JPanel();
JPanel panel3=new JPanel();
Box box=Box.createVerticalBox();
String s1="购物车",s2="";
public selectPanel(String user){
things=new ArrayList<thing2>();
JPanel panel1=new JPanel();
button0=new JButton("查询");button0.setFont(new Font("楷体",Font.PLAIN,20));button0.setContentAreaFilled(false);
label=new JLabel("商品名:");label.setFont(new Font("楷体",Font.PLAIN,20));label.setForeground(Color.blue);
field=new JTextField(50);field.setFont(new Font("楷体",Font.PLAIN,20));
panel1.add(label);panel1.add(field);panel1.add(button0);
JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setViewportView(box);
jp.setPreferredSize(new Dimension(780,700));
box.revalidate();
panel2.add(jp);
button1=new JButton("保存");button1.setFont(new Font("楷体",Font.PLAIN,20));button1.setContentAreaFilled(false);
button2=new JButton("取消");button2.setFont(new Font("楷体",Font.PLAIN,20));button2.setContentAreaFilled(false);
panel3.add(button1);panel3.add(button2);
setLayout(new BorderLayout());
add(panel1,BorderLayout.NORTH);
setSize(700,850);
button0.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
if(!field.getText().equals("")){
things.clear();
try{
File f1=new File("E:\java\编程\大作业\src\界面层\商品.txt");
FileInputStream fis=new FileInputStream(f1);
InputStreamReader dis=new InputStreamReader(fis);
BufferedReader reader=new BufferedReader(dis);
int i=0;String string;
String []str=new String[5];
while((string=reader.readLine())!=null){
str[i]=string;
i++;
if(i==5){
i=0;
if(str[1].equals(field.getText())){
thing2 th=new thing2(str,s1,s2);
box.add(th);
things.add(th);
}
}
}
reader.close();
}
catch(FileNotFoundException e1){
System.out.println(e1);
}
catch(IOException e1){
System.out.println(e1);
}
if(things.size()!=0){
add(panel2,BorderLayout.CENTER);
add(panel3,BorderLayout.SOUTH);
}
}
else{
JOptionPane.showMessageDialog(selectPanel.this, "请输入商品","请输入商品",JOptionPane.INFORMATION_MESSAGE);
}
setVisible(true);
}
}
);
}
}

梦醒如赦的主页 梦醒如赦 | 菜鸟二级 | 园豆:214
提问于:2021-07-02 11:02
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册