weB_KiLeR
Član broj: 238 Poruke: 1317 195.252.107.*
|
Heh ako hoces grid bag layout evo ti moj prog u kome imas to:
//by weB_KiLeR bak-bag team.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class program extends JFrame implements ActionListener, KeyListener
{
JMenuBar meni = new JMenuBar();
JPanel glavni = new JPanel();
JPanel sporedni = new JPanel();
JLabel al = new JLabel("ime");
JLabel bl = new JLabel("prezime");
JLabel cl = new JLabel("maticni broj");
// JLabel hal = new JLabel("Bolest zuba1");
JLabel ml = new JLabel("Bolest");
JTextField at = new JTextField("0",9);
JTextField bt = new JTextField("0",9);
JTextField ct = new JTextField("0",9);
JTextField mt = new JTextField("0",9);
// JComboBox hat = new JComboBox();
String ime[] = new String[20];
String prezime[] = new String[20];
String maticni_broj[] = new String[20];
String bolest[] = new String[20];
int index=0,pom;
String p;
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
///////////////////////////////////////
public program ()//CONSTRUCTOR
{
super("program");
glavni.setLayout(new BorderLayout());
sporedni.setLayout(gbl);
// hat.addItem("Karijes");
// hat.addItem("Erozija zuba");
// hat.addItem("Vadjenje zuba");
postavka (gbc, 0,0,1,1,25,16);
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gbl.setConstraints(al,gbc);
sporedni.add(al);
postavka (gbc, 1,0,1,1,25,16);
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbl.setConstraints(at,gbc);
sporedni.add(at);
postavka (gbc, 0,1,1,1,25,16);
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gbl.setConstraints(bl,gbc);
sporedni.add(bl);
postavka (gbc, 1,1,1,1,25,16);
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbl.setConstraints(bt,gbc);
sporedni.add(bt);
postavka (gbc, 0,2,1,1,25,16);
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gbl.setConstraints(cl,gbc);
sporedni.add(cl);
postavka (gbc, 1,2,1,1,25,16);
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbl.setConstraints(ct,gbc);
sporedni.add(ct);
/* postavka (gbc, 0,4,1,1,25,16);
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gbl.setConstraints(hal,gbc);
sporedni.add(hal);
postavka (gbc, 1,4,1,1,25,16);
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbl.setConstraints(hat,gbc);
sporedni.add(hat);
*/
postavka (gbc, 0,3,1,1,25,16);
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gbl.setConstraints(ml,gbc);
sporedni.add(ml);
postavka (gbc, 1,3,1,1,25,16);
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbl.setConstraints(mt,gbc);
sporedni.add(mt);
Meni();
glavni.add("North",meni);
setContentPane(glavni);
glavni.add("Center",sporedni);
}
public void postavka(GridBagConstraints gbc,int x,int y,int zx,int zy,int w,int h)
{
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = zx;
gbc.gridheight = zy;
gbc.weightx = w;
gbc.weighty = h;
}
public static void main(String[] arg)
{
JFrame Win1 = new program();
WindowListener wl = new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
};
Win1.addWindowListener(wl);
Win1.setSize(new Dimension(200,250));
Win1.setVisible(true);
}
public void Meni()
{
// JMenu Izgled = new JMenu("Izgled");
this.setJMenuBar(meni);
JMenu Fajlovi = new JMenu("Fajel");
Fajlovi.setMnemonic(KeyEvent.VK_M);
meni.add(Fajlovi);
JMenuItem novi = new JMenuItem("unesi");
novi.addActionListener(this);
Fajlovi.add(novi).setMnemonic(KeyEvent.VK_N);
Fajlovi.add(new JSeparator());
JMenuItem pretraga = new JMenuItem("pretraga");
pretraga.addActionListener(this);
Fajlovi.add(pretraga).setMnemonic(KeyEvent.VK_N);
Fajlovi.add(new JSeparator());
JMenuItem kraj = new JMenuItem("Kraj");
kraj.addActionListener(this);
Fajlovi.add(kraj).setMnemonic(KeyEvent.VK_K);
JMenu Help = new JMenu("Pomoc(Help)");
Help.setMnemonic(KeyEvent.VK_M);
meni.add(Help);
JMenuItem Serbian = new JMenuItem("Serbian");
pretraga.addActionListener(this);
Help.add(Serbian).setMnemonic(KeyEvent.VK_N);
/*
meni.add(Izgled);
JMenuItem Windows = new JMenuItem("Windows");
JMenuItem Java = new JMenuItem("Java");
JMenuItem Unix = new JMenuItem("Unix - Motif");
Windows.addActionListener(this);
Java.addActionListener(this);
Unix.addActionListener(this);
Izgled.add(Java).setMnemonic(KeyEvent.VK_J);
Izgled.add(Windows).setMnemonic(KeyEvent.VK_W);
Izgled.add(Unix).setMnemonic(KeyEvent.VK_U);
*/
}
/* public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand() == "Windows")
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}
catch (Exception e) { }
}
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}
catch (Exception e) { }
}
if(ae.getActionCommand() == "Java")
{
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
this.pack();
} catch (Exception e) { }
}
if(ae.getActionCommand() == "Unix - Motif")
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}
catch (Exception e) { }
}
}
}*/
public void keyTyped(KeyEvent e)
{
if(e.getKeyChar() == Event.ENTER)
{
}
}
public void keyReleased(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getActionCommand() == "unesi")
{
if (index<20)
{
ime[index]=at.getText();
prezime[index]=bt.getText();
maticni_broj[index]=ct.getText();
bolest[index]=mt.getText();
index++;
}
}
if(ae.getActionCommand() == "pretraga")
{
p=at.getText();
for(int i=0;i<20;i++)
{
if (p==ime)
{
pom=i;
}
}
at.setText(ime[pom]);
bt.setText(prezime[pom]);
ct.setText(maticni_broj[pom]);
mt.setText(bolest[pom]);
}
if(ae.getActionCommand() == "Kraj")
{
this.hide();
System.exit(0);
}
if(ae.getActionCommand() == "Serbian")
{
}
if(ae.getActionCommand() == "English")
{
}
}
}
|