Пример #1
0
 @Override
 public void mouseClicked(MouseEvent e) {
   // TODO Auto-generated method stub
   if (e.getSource() == table) {
     if (e.getClickCount() == 2) // 더블클릭
     {
       int row = table.getSelectedRow();
       String no = model.getValueAt(row, 0).toString();
       bp.setPoster(Integer.parseInt(no));
       bp.repaint();
       Book book = bm.bookDetail(Integer.parseInt(no));
       la1.setText("번호:" + no);
       la2.setText("제목:" + book.getTitle());
       la3.setText("저자:" + book.getAuthor());
       la4.setText("출판사:" + book.getPublisher());
       la5.setText("가격:" + book.getPrice());
     }
   } else if (e.getSource() == b) {
     getData();
   }
 }
Пример #2
0
  public BookMain() {
    String[] col = {"번호", "제목", "저자"};
    String[][] row = new String[0][3];
    model =
        new DefaultTableModel(row, col) {
          // 익명의 클래스 : 변경,추가
          public boolean isCellEditable(int r, int c) {
            return false;
          }
        };
    table = new JTable(model);
    JScrollPane js = new JScrollPane(table);
    la1 = new JLabel("번호:");
    la2 = new JLabel("제목:");
    la3 = new JLabel("저자:");
    la4 = new JLabel("출판사:");
    la5 = new JLabel("가격:");

    la6 = new JLabel("Search");
    box = new JComboBox();
    box.addItem("위키북스");
    box.addItem("한빛미디어");
    box.addItem("영진출판사");
    box.addItem("대림출판사");
    tf = new JTextField(20);
    tf.setEditable(false);
    b = new JButton("전체목록");
    // <input type=text readonly>
    JPanel p = new JPanel();
    p.add(la6);
    p.add(box);
    p.add(tf);
    p.add(b);
    // 배치
    setLayout(null);
    p.setBounds(10, 15, 620, 35);
    js.setBounds(10, 55, 620, 245);
    bp.setBounds(10, 320, 300, 170);
    la1.setBounds(320, 320, 300, 30);
    la2.setBounds(320, 355, 300, 30);
    la3.setBounds(320, 390, 300, 30);
    la4.setBounds(320, 425, 300, 30);
    la5.setBounds(320, 460, 300, 30);
    add(p);
    add(js);
    add(bp);
    add(la1);
    add(la2);
    add(la3);
    add(la4);
    add(la5);

    setSize(640, 550);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getData();
    getData();
    table.addMouseListener(this);
    box.addItemListener(this);
    b.addMouseListener(this);
  }