欢迎来到天天文库
浏览记录
ID:37861151
大小:41.50 KB
页数:8页
时间:2019-06-01
《java列表项的增加与删除》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、25列表项的增加与删除.docpackagecom.swing01;importjava.awt.BorderLayout;importjava.awt.EventQueue;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.DefaultListModel;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JList;impo
2、rtjavax.swing.JOptionPane;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.UIManager;importjavax.swing.border.EmptyBorder;publicclassDynamicListextendsJFrame{privatestaticfinallongserialVersionUID=890359141688419648L;privateJPanelcontentPane;privateJListlist;//列表模型pr
3、ivateDefaultListModelmodel=newDefaultListModel();publicstaticvoidmain(String[]args){try{//皮肤UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Throwablee){e.printStackTrace();}EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{DynamicListframe=newDynam
4、icList();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicDynamicList(){//标题setTitle("列表项的增加与删除");//退出时关闭虚拟机setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//位置及大小setBounds(100,100,450,300);//面板容器contentPane=newJPanel();//面板边框contentPane.setBorde
5、r(newEmptyBorder(5,5,5,5));//面板布局格式contentPane.setLayout(newBorderLayout(0,0));//将面板容器添加到窗体中setContentPane(contentPane);//面板JPanelpanel=newJPanel();//将面板添加到容器中contentPane.add(panel,BorderLayout.SOUTH);//接钮JButtonaddButton=newJButton("增加");addButton.addActionListener(newActionListener(){publ
6、icvoidactionPerformed(ActionEvente){do_addButton_actionPerformed(e);}});//按钮字体addButton.setFont(newFont("微软雅黑",Font.PLAIN,16));//将面板添加按钮panel.add(addButton);//按钮JButtondeleteButton=newJButton("删除");deleteButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){do
7、_deleteButton_actionPerformed(e);}});//按钮设置字体deleteButton.setFont(newFont("微软雅黑",Font.PLAIN,16));//面板添加按钮panel.add(deleteButton);//滚动条JScrollPanescrollPane=newJScrollPane();//容器面板添加滚动条contentPane.add(scrollPane,BorderLayout.CENTER);//列表list=newJList();//
此文档下载收益归作者所有