Java problem z GUI

0
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class BookList extends JFrame implements ActionListener {

        JButton Exit,Dodaj,Góra,Dół;
        JButton WypożyczAndOddaj1,Usuń1;
        JButton WypożyczAndOddaj2,Usuń2;
        JButton WypożyczAndOddaj3,Usuń3;
        JButton WypożyczAndOddaj4,Usuń4;
        JButton WypożyczAndOddaj5,Usuń5;
        JButton WypożyczAndOddaj6,Usuń6;
        JButton WypożyczAndOddaj7,Usuń7;
        JButton WypożyczAndOddaj8,Usuń8;
        JButton WypożyczAndOddaj9,Usuń9;
        JButton WypożyczAndOddaj10,Usuń10;

        JTable TabelaDodania,TabelaKsiązek;

 BookList(){

      super("System Bilbioteczny - Lista Ksiązek");
     setSize(920,400);
     setVisible(true);
     setResizable(false);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


       Container kontener = getContentPane();
                 kontener.setLayout(null);

        Dodaj = new JButton("Dodaj");
     Dodaj.setBounds(480,20,200,20);
     Dodaj .addActionListener(this);
    kontener.add(Dodaj);

      Góra = new JButton("Góra");
     Góra.setBounds(400,280,70,20);
     Góra.addActionListener(this);
    kontener.add(Góra);
    
      Dół = new JButton("Dół");
     Dół.setBounds(400,300,70,20);
     Dół.addActionListener(this);
    kontener.add(Dół);

        Exit = new JButton("Cofnij");
     Exit.setBounds(700,340,200,20);
      Exit.addActionListener(this);
    kontener.add(Exit);

      TabelaDodania = new JTable(1,8);
     TabelaDodania.setBounds(20,20,450,20);
    kontener.add(TabelaDodania);

     TabelaKsiązek = new JTable(10,8);
     TabelaKsiązek.setBounds(20,40,450,160);
    kontener.add(TabelaKsiązek);



    WypożyczAndOddaj1 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj1.setBounds(480,40,200,20);
     WypożyczAndOddaj1.addActionListener(this);
    kontener.add(WypożyczAndOddaj1);

    WypożyczAndOddaj2 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj2.setBounds(480,60,200,20);
     WypożyczAndOddaj2.addActionListener(this);
    kontener.add(WypożyczAndOddaj2);

    WypożyczAndOddaj3 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj3.setBounds(480,80,200,20);
     WypożyczAndOddaj3.addActionListener(this);
    kontener.add(WypożyczAndOddaj3);

    WypożyczAndOddaj4 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj4.setBounds(480,100,200,20);
     WypożyczAndOddaj4.addActionListener(this);
    kontener.add(WypożyczAndOddaj4);

    WypożyczAndOddaj5 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj5.setBounds(480,120,200,20);
     WypożyczAndOddaj5.addActionListener(this);
    kontener.add(WypożyczAndOddaj5);

    WypożyczAndOddaj6 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj6.setBounds(480,140,200,20);
     WypożyczAndOddaj6.addActionListener(this);
    kontener.add(WypożyczAndOddaj6);

    WypożyczAndOddaj7 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj7.setBounds(480,160,200,20);
     WypożyczAndOddaj7.addActionListener(this);
    kontener.add(WypożyczAndOddaj7);

    WypożyczAndOddaj8 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj8.setBounds(480,180,200,20);
     WypożyczAndOddaj8.addActionListener(this);
    kontener.add(WypożyczAndOddaj8);

    WypożyczAndOddaj9 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj9.setBounds(480,200,200,20);
     WypożyczAndOddaj9.addActionListener(this);
    kontener.add(WypożyczAndOddaj9);

    WypożyczAndOddaj10 = new JButton("WypożyczAndOddaj");
     WypożyczAndOddaj10.setBounds(480,220,200,20);
     WypożyczAndOddaj10.addActionListener(this);
    kontener.add(WypożyczAndOddaj10);

    Usuń1 = new JButton("Usuń");
     Usuń1.setBounds(700,40,200,20);
     Usuń1.addActionListener(this);
    kontener.add(Usuń1);

    Usuń2 = new JButton("Usuń");
     Usuń2.setBounds(700,60,200,20);
     Usuń2.addActionListener(this);
    kontener.add(Usuń2);

    Usuń3 = new JButton("Usuń");
     Usuń3.setBounds(700,80,200,20);
     Usuń3.addActionListener(this);
    kontener.add(Usuń3);

    Usuń4 = new JButton("Usuń");
     Usuń4.setBounds(700,100,200,20);
     Usuń4.addActionListener(this);
    kontener.add(Usuń4);

    Usuń5 = new JButton("Usuń");
     Usuń5.setBounds(700,120,200,20);
     Usuń5.addActionListener(this);
    kontener.add(Usuń5);

    Usuń6 = new JButton("Usuń");
     Usuń6.setBounds(700,140,200,20);
     Usuń6.addActionListener(this);
    kontener.add(Usuń6);

    Usuń7 = new JButton("Usuń");
     Usuń7.setBounds(700,160,200,20);
     Usuń7.addActionListener(this);
    kontener.add(Usuń7);

    Usuń8 = new JButton("Usuń");
     Usuń8.setBounds(700,180,200,20);
     Usuń8.addActionListener(this);
    kontener.add(Usuń8);

    Usuń9 = new JButton("Usuń");
     Usuń9.setBounds(700,200,200,20);
     Usuń9.addActionListener(this);
    kontener.add(Usuń9);

    Usuń10 = new JButton("Usuń");
     Usuń10.setBounds(700,220,200,20);
     Usuń10.addActionListener(this);
    kontener.add(Usuń10);

  

  repaint();  // to poprawia "widoczność", inaczej bym musiał tutaj walnąć setVisible -> ze na koncu musi byc.
    }
  public void actionPerformed(ActionEvent e){

      if(e.getSource() == Exit)  {
     int wybor = JOptionPane.showConfirmDialog(null,"Cofnąć do menu głownego?","System biblioteczny",0);
     if(wybor == JOptionPane.OK_OPTION){                       //JOptionPane.PLAIN_MESSAGE);JOptionPane.QUESTION_MESSAGE);JOptionPane.WARNING_MESSAGE)
     dispose();                                               //;JOptionPane.INFORMATION_MESSAGE);JOptionPane.ERROR_MESSAGE);
     new MainInterface();
     }
     else{
      return;
     }
      }
     if(e.getSource() == Usuń1){
      int wybor1 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor1 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń2){
      int wybor2 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor2 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń3){
      int wybor3 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor3 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń4){
      int wybor4 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor4 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń5){
      int wybor5 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor5 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń6){
      int wybor6 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor6 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń7){
      int wybor7 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor7 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń8){
      int wybor8 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor8 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń9){
      int wybor9 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor9 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
      if(e.getSource() == Usuń10){
      int wybor10 = JOptionPane.showConfirmDialog(null,"Czy napewno chcesz usunąć książke?","Potwierdzenie usunięcia",0);
      if(wybor10 == JOptionPane.OK_OPTION){
         }
     else{
      return;
     }}
     }

      
  
 public static void main(String []arg){
     new BookList();
 }


}

jest to kod do graficznego interfejsu części programu, nie wiem w jaki sposób ustawić nagłówki nad każdą z tabel

0

Weź przemyśl całą budowę takiego GUI.
A jeśli potrzebujesz już tak dużej liczby tych samych komponentów, to wrzuć to do kolekcji/tablicy.
Skróć ten kod jak bozia przykazała wtedy będzie można coś wyczytać z tego.
Poczytaj sobie o zasadzie DRY.

1 użytkowników online, w tym zalogowanych: 0, gości: 1