Za kakeršen koli nasvet se zahvaljujem
package components;
import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;
/* ComboBoxDemo2.java requires no other files. */
public class ComboBoxDemo2 extends JPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
static JFrame frame;
JLabel result;
JButton start;
JComboBox mesecBox;
JComboBox letoBox;
String currentPattern = "";
String currentPattern1 = "";
Integer IzbraniMesec;
Integer IzbranoLeto;
public ComboBoxDemo2() {
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
String[] meseci = { "izberi mesec",
"Januar",
"Februar",
"Marec",
"April",
"Maj",
"Junij",
"Julij",
"Avgust",
"September",
"Oktober",
"November",
"December"};
String[] leta = {"2009",
"2010",
"2011",
"2012",
"2013",
"2014",
"2015"};
currentPattern = meseci[0];
currentPattern1 = leta[0];
JLabel mesec = new JLabel("Mesec:");
JLabel leto = new JLabel("Leto:");
//Set up the UI for selecting a pattern.
JComboBox mesecBox = new JComboBox(meseci);
mesecBox.setEditable(true);
mesecBox.addActionListener(this);
JComboBox letoBox = new JComboBox(leta);
letoBox.setEditable(true);
letoBox.addActionListener(this);
start = new JButton();
start.setText("start");
start.addActionListener(this);
//Lay out everything.
JPanel patternPanel = new JPanel();
patternPanel.setLayout(new BoxLayout(patternPanel,BoxLayout.PAGE_AXIS));
patternPanel.add(mesec);
mesecBox.setAlignmentX(Component.LEFT_ALIGNMENT);
patternPanel.add(mesecBox);
JPanel patternPanel1 = new JPanel();
patternPanel1.setLayout(new BoxLayout(patternPanel1,BoxLayout.PAGE_AXIS));
patternPanel1.add(leto);
letoBox.setAlignmentX(Component.LEFT_ALIGNMENT);
patternPanel1.add(letoBox);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.PAGE_AXIS));
buttonPanel.add(start);
patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
patternPanel1.setAlignmentX(Component.LEFT_ALIGNMENT);
add(patternPanel);
add(Box.createRigidArea(new Dimension(0, 10)));
add(patternPanel1);
add(Box.createRigidArea(new Dimension(0, 10)));
add(buttonPanel);
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
reformat(currentPattern);
reformatLeto(currentPattern1);
} //constructor
public void actionPerformed(ActionEvent e) {
if(e.getSource() == start);{
currentPattern = (String)mesecBox.getSelectedItem();
currentPattern1 = (String)letoBox.getSelectedItem();
IzbraniMesec = reformat(currentPattern);
IzbranoLeto = reformatLeto(currentPattern1);
}
}
/** Formats and displays today's date. */
public static int reformat(String currentPattern) {
int a=0;
String m = currentPattern;
if(m=="izberi mesec") a=0;
else if(m=="Januar") a=1;
else if(m=="Februar") a=2;
else if(m=="Marec") a=3;
else if(m=="April") a=4;
else if(m=="Maj") a=5;
else if(m=="Junij") a=6;
else if(m=="Julij") a=7;
else if(m=="Avgust") a=8;
else if(m=="September") a=9;
else if(m=="Oktober") a=10;
else if(m=="November") a=11;
else if(m=="December") a=12;
return a;
}
//reformats chosen year to integer
public static int reformatLeto(String currentPattern1){
int a=0;
a = Integer.valueOf(currentPattern1);
if(currentPattern1 == "izberi leto"){
a=0;
}
return a;
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ComboBoxDemo2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new ComboBoxDemo2();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); }}










