privatestaticclassTeammember{publicTeammember()throwsUnsupportedEncodingException,FileNotFoundException,IOException{Stringencoding="GBK";JFrameframe=newJFrame("队员");fra...
private static class Teammember {
public Teammember() throws UnsupportedEncodingException, FileNotFoundException, IOException {
String encoding = "GBK";
JFrame frame=new JFrame("队员");
frame.setSize(300, 200);
JPanel panel=new JPanel();
JLabel label=new JLabel("输入查询的球队: 例如:巴西队员");
String[] str={"巴西队员","法国队员","美国队员"};
JComboBox comboBox=new JComboBox(str);
frame.add(panel);
JButton button=new JButton("确定");
button.addActionListener(comboBox);
panel.add(label,BorderLayout.CENTER);
panel.add(comboBox,BorderLayout.LINE_END);
frame.setVisible(true);
这块如何触发button:if(e.getsourse()==button)
String mem=comboBox.getSelectedItem().toString();
File file = new File("E:\\数据结构\\队员\\"+mem+".txt");
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
String sumLine = "";
while ((lineTXT = bufferedReader.readLine()) != null) {
sumLine = sumLine+lineTXT.toString().trim()+"\n";
}
read.close();
JFrame frame1=new JFrame("射手榜");
frame1.setSize(600, 500);
JTextArea textArea=new JTextArea();
JScrollPane jScrollPane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame1.add(jScrollPane);
textArea.setText(sumLine);
frame1.setVisible(true);
// textArea.setText(sumLine);
}
}
展开