修改版

package one;
 
import java.awt.*;
import java.awt.event.*;
import java.sql.SQLException;
 
import javax.swing.*;
 
@SuppressWarnings({ "serial", "unused" })
public class etg extends JDialog implements ActionListener{
  private JLabel bookNumLabel;
  private JLabel bookNameLabel;
  private JLabel bookWriterLabel;
  private JLabel bookPublishLabel;
  private JLabel bookPriceLabel;
  private JLabel bookTimeLabel;
  private JTextField bookNumText;
  private JTextField bookNameText;
  private JTextField bookWriterText;
  private JTextField bookPublishText;
  private JTextField bookPriceText;
  private JTextField bookTimeText;
    
  private JButton submitBut;
  private JButton cancelBut;
  public etg(Frame owner,String title,boolean model){
    //父窗口,窗口名,是否是模式窗口
    super(owner,title,model);
    bookNumLabel=new JLabel("书  号:");
    bookNameLabel=new JLabel("书  名:");
    bookWriterLabel=new JLabel("作  者:");
    bookPublishLabel=new JLabel("出版社:");
    bookPriceLabel=new JLabel("价  格:");
    bookTimeLabel=new JLabel("出版时间:");
      
    bookNumText=new JTextField(10);
    bookNameText=new JTextField(10);
    bookWriterText=new JTextField(10);
    bookPublishText=new JTextField(10);
    bookPriceText=new JTextField(10);
    bookTimeText=new JTextField(9);
      
    submitBut=new JButton("确认");
    cancelBut=new JButton("取消");
    submitBut.addActionListener(this);
    cancelBut.addActionListener(this);
    this.setBounds(350,150,400,260);
    this.setResizable(false);
    this.setLayout(new BorderLayout());
    initLayout();
  }
  public void initLayout(){
    Container[] con1=new Container[6];
    for(int i=0;i<6;i++) con1[i]=new Container();
    con1[0].setLayout(new FlowLayout());
    con1[0].add(bookNumLabel);
    con1[0].add(bookNumText);
      
    con1[1].setLayout(new FlowLayout());
    con1[1].add(bookNameLabel);
    con1[1].add(bookNameText);
      
    con1[2].setLayout(new FlowLayout());
    con1[2].add(bookWriterLabel);
    con1[2].add(bookWriterText);
      
    con1[3].setLayout(new FlowLayout());
    con1[3].add(bookPublishLabel);
    con1[3].add(bookPublishText);
      
    con1[4].setLayout(new FlowLayout());
    con1[4].add(bookPriceLabel);
    con1[4].add(bookPriceText);
      
    con1[5].setLayout(new FlowLayout());
    con1[5].add(bookTimeLabel);
    con1[5].add(bookTimeText);
      
    Container con2=new Container();
    con2.setLayout(new BorderLayout());
    con2.add(con1[0],BorderLayout.NORTH);
    con2.add(con1[1],BorderLayout.CENTER);
    con2.add(con1[2],BorderLayout.SOUTH);
      
    Container con3=new Container();
    con3.setLayout(new BorderLayout());
    con3.add(con1[3],BorderLayout.NORTH);
    con3.add(con1[4],BorderLayout.CENTER);
    con3.add(con1[5],BorderLayout.SOUTH);
      
    Container con4=new Container();
    con4.setLayout(new FlowLayout());
    con4.add(submitBut);
    con4.add(cancelBut);
    Container con5=new Container();
    con5.setLayout(new BorderLayout());
    con5.add(con2,BorderLayout.NORTH);
    con5.add(con3,BorderLayout.CENTER);
    con5.add(con4,BorderLayout.SOUTH);
      
    this.add(con5,BorderLayout.CENTER);
    this.validate();
    this.setVisible(true);
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    if(e.getSource()==submitBut){
      if(bookNumText.getText().equals("")||bookNameText.getText().equals("")||
          bookWriterText.getText().equals("")||bookPublishText.getText().equals("")||
          bookPriceText.getText().equals("")||bookTimeText.getText().equals("")){
        //System.out.println("输入失败");
        JOptionPane.showMessageDialog(this,"输入不能有空", "提示",JOptionPane.PLAIN_MESSAGE);
      }
      else{
        //System.out.println("输入成功");
        String sql="insert into "
            + "book_info(book_num,book_name,book_writer,publish_house,book_price,publish_time)"
            + "values('"+bookNumText.getText()+"','"+bookNameText.getText()+"','"+bookWriterText.getText()+"','"+bookPublishText.getText()+"','"+bookPriceText.getText()+"','"+bookTimeText.getText()+"')";
        BookTableModel book=new BookTableModel();
         // ((Object) book)(sql);  
        JOptionPane.showMessageDialog(this,"添加成功", "提示",JOptionPane.PLAIN_MESSAGE);
        this.setVisible(false);
      }
    }
    if(e.getSource()==cancelBut){
      this.setVisible(false);
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值