Kako 'necce'.
Code:
import java.awt.BorderLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author Velja Radenkovic
* class: MainForm
* package:
*/
public class MainForm extends JFrame{
/*
* Private fields
*/
private JPanel mainPanel;
private JComboBox combo;
private JButton button;
/**
* Default constructor
*/
public MainForm(){this.initalize();}
//
//Entry point
//
public static void main(String[] args)
{
System.out.println("Program started!");
MainForm mainFrm = new MainForm();
mainFrm.pack();
mainFrm.setSize(800, 600);
mainFrm.setVisible(true);
}
/*
* Initalize ui
*/
private void initalize()
{
this.setContentPane(this.getMainPanel());
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/*
* gets the mainPanel
*/
private JPanel getMainPanel()
{
if(this.mainPanel == null)
{
this.mainPanel = new JPanel();
this.mainPanel.setLayout(new BorderLayout(10, 10));
this.mainPanel.add(this.getCombo(), BorderLayout.NORTH);
this.mainPanel.add(this.getButton(), BorderLayout.CENTER);
}
return this.mainPanel;
}
/*
* gets the combo
*/
private JComboBox getCombo()
{
if(this.combo == null)
{
this.combo = new JComboBox();
this.combo.addItem("Stavka jedan");
this.combo.addItem("Stavka dva");
this.combo.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
System.out.println("Key released!");
}
});
}
return this.combo;
}
/*
*
*/
private JButton getButton()
{
if(this.button == null)
{
this.button = new JButton("Klikni me klikni");
}
return this.button;
}
}
Kazi kad 'oce' da maknem nepotreban deo koda.