实验04 - Java输入输出流报告 联系客服

发布时间 : 星期三 文章实验04 - Java输入输出流报告更新完毕开始阅读526943c9c8d376eeaeaa3195

* Launch the application. */

public static void main(String[] args) { } /**

* Create the frame. */

public test() {

setTitle(\登录\

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel name = new JLabel(\用户名\

name.setFont(new Font(\宋体\name.setBounds(118, 28, 62, 21); contentPane.add(name); textField = new JTextField();

textField.setFont(new Font(\宋体\textField.setBounds(180, 29, 122, 21);

- 17 -

EventQueue.invokeLater(new Runnable() { });

public void run() { }

try {

test frame = new test(); frame.setVisible(true);

} catch (Exception e) { }

e.printStackTrace();

contentPane.add(textField); textField.setColumns(10);

JLabel password = new JLabel(\密 码\

password.setFont(new Font(\宋体\password.setBounds(118, 72, 62, 21); contentPane.add(password);

JButton btnNewButton = new JButton(\登录\

btnNewButton.setFont(new Font(\宋体\btnNewButton.addActionListener(new ActionListener() { });

btnNewButton.setBounds(118, 130, 62, 23); contentPane.add(btnNewButton); JButton button = new JButton(\清空\

button.setFont(new Font(\宋体\button.addActionListener(new ActionListener() { });

- 18 -

public void actionPerformed(ActionEvent e) { }

String name = \String password = \

String str = new String(textField.getText()); String pw = new String(passwordField.getPassword()); if (str.equals(name) && (pw.equals(password))) { } else { }

JOptionPane.showMessageDialog(null, \登录失败!\

JOptionPane.showMessageDialog(null, \恭喜你,登录成功!!!\

public void actionPerformed(ActionEvent e) { }

textField.setText(\passwordField.setText(\

}

}

button.setBounds(240, 130, 62, 23); contentPane.add(button);

passwordField = new JPasswordField();

passwordField.setBounds(180, 73, 122, 21); contentPane.add(passwordField);

一道添加题:JButton button = new JButton(\添加\);

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

for(int i = 0;i<2;i++){ }

Person p = new Person(textid.getText(),textname.getText()); //hs = new HashSet(); hs.add(p);

textname.setText(\); textid.setText(\);

}

一道显示题:JButton button_1 = new JButton(\显示\);

button_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) { }

Iterator it = hs.iterator(); StringBuilder sb = new StringBuilder(); while(it.hasNext())

textArea.setText(new String(sb));

sb.append(it.next());

});

实验题2 在文本框中输入目录,点击“转到”按钮,将该目录中的文件与文件夹名称列在下面的文本区域中,简单查询界面如图9-4所示。

- 19 -

图 9-4 文件列表

package L2;

import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel;

import javax.swing.border.EmptyBorder; import javax.swing.JLabel;

import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JTextArea;

import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.File; import java.awt.Font;

public class FileSeach extends JFrame {

private JPanel contentPane; private JTextField textField;

private JTextArea textArea = new JTextArea(); private JScrollPane scrollPane = new JScrollPane(); /**

* Launch the application. */

public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { FileSeach frame = new FileSeach(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /**

* Create the frame. */

- 20 -