📄 frame1.java~12~
字号:
package list;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); Panel panel1 = new Panel(); TextField textField1 = new TextField(); Button button1 = new Button(); Button button2 = new Button(); TextArea textArea1 = new TextArea(); List l = null,p; /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(328, 249)); this.setTitle("在Java中实现链表"); button1.setLabel("Add"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setLabel("List"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); textField1.setColumns(10); textArea1.setBackground(Color.lightGray); textArea1.setEditable(false); contentPane.add(panel1, BorderLayout.NORTH); panel1.add(textField1, null); panel1.add(button1, null); panel1.add(button2, null); contentPane.add(textArea1, BorderLayout.CENTER); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void button1_actionPerformed(ActionEvent e) { String data = new String(textField1.getText()); if (data!= null){ p = new List(textField1.getText()); if( l == null ) l = p; else l = p.add( l ); textField1.setText(""); textField1.requestFocus(); } } void button2_actionPerformed(ActionEvent e) { textArea1.setText(""); textArea1.setText(l.toString()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -