1、4. 输出模块5. 6. 源程序如下1.mainframe.javapackage bookmanager;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.LinkedL
2、ist;public class mainframe extends JFrame implements ActionListenerprivate JToolBar tb;String btntitle=增加,查询删除退出;String tabeltitle=图书编号书名定价出版社JButton btn=new JButton4;JTable table; DefaultTableModel model;public mainframe() super(图书管理系统); /初始化各个按钮 tb=new JToolBar(工具栏 for(int i=0;ibtntitle.length;i+)
3、 btni=new JButton(btntitlei); btni.addActionListener(this); tb.add(btni); /创建表模型 model=new DefaultTableModel(tabeltitle,10); table=new JTable(model); /设定单元格的高度 table.setRowHeight(25); add(tb,BorderLayout.NORTH ); add(new JScrollPane(table),BorderLayout.CENTER ); setSize(900,600); setDefaultCloseOper
4、ation(JFrame.EXIT_ON_CLOSE ); setLocation(100,30); init();public void actionPerformed(ActionEvent e) mainframe m=new mainframe(); Object o=e.getSource(); if(o=btn0) adddialog ad=new adddialog(m,25,25); init(); if(o=btn1) searchdialog sd=new searchdialog(m,25,25); sd.dialog.setVisible(true); init();
5、if(o=btn2) int result=JOptionPane.showConfirmDialog(null,确实要删除该条图书信息吗?确认,JOptionPane.YES_NO_OPTION ,JOptionPane.QUESTION_MESSAGE ); if(result=0) Connection con=dbcon.getconnectin(); Object ob=model.getValueAt(table.getSelectedRow(),0); dbcon.delete(con,ob); init(); else return ; if(o=btn3) System.ex
6、it(0);public void init() Connection con=dbcon.getconnectin(); LinkedList list=null; try PreparedStatement stmt=con.prepareStatement(select * from book ResultSet rs=stmt.executeQuery(); list=new LinkedList(); while(rs.next() String id=rs.getString(1); String name=rs.getString(2); String price=rs.getS
7、tring(3); String publish=rs.getString(4); book b=new book(id,name,Float.valueOf(price),publish); list.add(b); model.setRowCount(0); for(int i=0;list.size(); book b=(book)list.get(i); Object str=b.getid(),b.getname(),b.getprice(),b.getpublish(); model.addRow(str); catch (SQLException e) / TODO Auto-g
8、enerated catch block e.printStackTrace(); public static void main(String args)new mainframe().show();*2.Adddialog.java添加模块public class adddialog implements ActionListener JLabel label=new JLabel4;JTextField txt=new JTextField4;String ltitle=图书名称单 价出 版 社String btitle=上一个下一个确 定取 消JDialog dialog;JPanel
9、 p;LinkedList list;public adddialog(JFrame f,int x,int y) dialog=new JDialog(f,true); dialog.setLocation(x,y); p=new JPanel(); list=new LinkedList();/ p.setBorder(BorderFactory.createTitledBorder(请选择操作);/ p.setBorder(BorderFactory.createLineBorder(Color.red );/ p.setBorder(BorderFactory.createBevelB
10、order(0, Color.red , Color.green ); p.setBorder(BorderFactory.createBevelBorder(0, Color.red , Color.green , Color.blue , Color.yellow );ltitle.length ; labeli=new JLabel(ltitlei); labeli.setFont(new Font(宋体,Font.PLAIN ,18); txti=new JTextField(); btni=new JButton(btitlei); btni.setFont(new Font(幼圆,
11、Font.PLAIN ,15); dialog.add(labeli); dialog.add(txti); dialog.add(btni); dialog.setLayout(null); p.setBounds(10,150,310,160); p.setBackground(Color.green ); label0.setBounds(10,10,90,25);txt0.setBounds(110,10,200,25); label1.setBounds(10,45,90,25);txt1.setBounds(110,45,200,25); label2.setBounds(10,8
12、0,90,25);txt2.setBounds(110,80,200,25); label3.setBounds(10,115,90,25);txt3.setBounds(110,115,200,25); dialog.add(p); btn0.setBounds(60,180,80,25);btn1.setBounds(175,180,80,25); btn2.setBounds(60,250,80,25);btn3.setBounds(175,250,80,25); dialog.setSize(400,400); dialog.show(); dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE ); int size=list.size();/ init();/ list.add(b);/ if(
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1