Advertisement
Guest User

hmh1

a guest
Apr 13th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.51 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package jonth_swingtenta;
  6.  
  7. import java.awt.*;
  8. import javax.swing.*;
  9. import javax.xml.bind.Marshaller.Listener;
  10.  
  11. /**
  12.  *
  13.  * @author h12mjont
  14.  */
  15. public class PanelGUI extends JPanel {
  16.     private JPanel panel;
  17.     private GridBagConstraints c;
  18.     private GridBagLayout gridBag;
  19.     private JLabel variID, varuNamn, varuKat;
  20.     private JTextField textField1, textField2;
  21.     private JTextArea textArea1;
  22.     private JButton laggTill, taBort, uppdatera, sokPaID, sokKat;
  23.     private Listener listener;
  24.     private DAOFactory daofactory;
  25.     private DAOInterface dao;
  26.     private JComboBox markeBox;
  27.     String[] marken = {"Frukt", "Mejeri", "Kött"};
  28.    
  29.     public PanelGUI(){
  30.        
  31.         panel = new JPanel(); //Skapar en ny panel där alla komponeneter ska finnas.
  32.         gridBag = new GridBagLayout(); //Skapar en gridbaglayout
  33.         c = new GridBagConstraints(); //Skapar constraints.
  34.         panel.setLayout(gridBag); //Sätter layouten.
  35.        
  36.        
  37.         //----------------col 1-----------------------------------
  38.        
  39.        
  40.         variID = new JLabel("Varu ID");
  41.         laggTillGUIGridBag(variID, 0,0,1,1);
  42.        
  43.         varuNamn = new JLabel("Varunamn");
  44.         laggTillGUIGridBag(varuNamn, 1,0,1,1);
  45.        
  46.         varuKat = new JLabel("Varukategori");
  47.         laggTillGUIGridBag(varuKat, 2,0,1,1);
  48.        
  49.         laggTill = new JButton("Lägg till");
  50.         laggTillGUIGridBag(laggTill, 3,0,1,1);
  51.        
  52.         uppdatera = new JButton("Uppdatera");
  53.         laggTillGUIGridBag(uppdatera, 4,0,1,1);
  54.        
  55.         sokKat = new JButton("Sök på Kategori");
  56.         laggTillGUIGridBag(sokKat, 5,0,2,1);
  57.        
  58.        
  59.         //-----------------col 2--------------------------------
  60.         textField1 = new JTextField();
  61.         textField1.setPreferredSize(new Dimension(70,20));
  62.         laggTillGUIGridBag(textField1, 0,1,2,1);
  63.        
  64.         textField2 = new JTextField();
  65.         textField2.setPreferredSize(new Dimension(70,20));
  66.         laggTillGUIGridBag(textField2, 1,1,2,1);
  67.        
  68.         markeBox = new JComboBox();
  69.         markeBox.setModel(new DefaultComboBoxModel(marken));
  70.      // markeBox.addItemListener(combolyssnare);
  71.         markeBox.setPreferredSize(new Dimension(70,20));
  72.         laggTillGUIGridBag(markeBox, 2,1,1,1);
  73.        
  74.         taBort = new JButton("Ta bort");
  75.         laggTillGUIGridBag(taBort, 3,1,1,1);
  76.        
  77.         sokPaID = new JButton("Sök på id");
  78.         laggTillGUIGridBag(sokPaID, 4,1,1,1);
  79.        
  80.        
  81.         //-------------------col 3--------------------------------
  82.         textArea1 = new JTextArea();
  83.         textArea1.setPreferredSize(new Dimension(350,100));
  84.         textArea1.setMinimumSize(new Dimension(350,100));
  85.         laggTillGUIGridBag(textArea1, 0, 3, 2, 2);
  86.        
  87.        
  88.         //----------------Slut på GUI ----------------------------
  89.        
  90.         add(panel);
  91. }
  92.    
  93.      private void laggTillGUIGridBag(Component guiKomponent, int rad, int kolumn, int bredd, int hojd){
  94.    
  95.         c.fill= GridBagConstraints.BOTH; //Gör så komponenten fyller ut sig i storlek åt båda håll.
  96.         c.gridx= kolumn;
  97.         c.gridy=rad;
  98.         c.gridwidth=bredd;
  99.         c.gridheight=hojd;
  100.         c.insets=new Insets(5,5,5,5); //Sätter padding runt komponenten
  101.         gridBag.setConstraints(guiKomponent, c);
  102.         panel.add(guiKomponent,c);
  103.    
  104.         }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement