I want to create something like the image below, when the user select the year, the month and the day from the Combobox options, those actions will change the Title and it has to change according to the selected data, it's something simple, I am still newbie
So far I have done this, the problem is that it does't work, how can I make it?, could you help me please?
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class DateForm_Complete extends JFrame {
private JLabel year, month, day;
private JComboBox cmonth, cday, cyear;
public DateForm_Complete() {
setTitle("Date Selection");
setSize(400,100);
setupWidgets();
setVisible(true);
}
private void setupWidgets() {
year= new JLabel("Year");
month= new JLabel("Month");
day= new JLabel("Day");
cyear= new JComboBox();
cmonth= new JComboBox();
cday= new JComboBox();
setLayout(new GridLayout (2,3));
add(year); add(month); add(day);
add(cyear); add(cmonth); add(cday);
for (int i=1900; i<2019; i++)
{
cyear.addItem(i);
}
String months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
for (int i=0; i<12; i++)
{
cmonth.addItem(months[i]);
}
for (int i=1; i<32; i++)
{
cday.addItem(i);
}
setupEvents();
}
private void setupEvents() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
cyear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
JComboBox combo = (JComboBox)ev.getSource();
String texty = (String)combo.getSelectedItem();
}
});
cmonth.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
JComboBox combo = (JComboBox)ev.getSource();
String textm = (String)combo.getSelectedItem();
}
});
cday.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
JComboBox combo = (JComboBox)ev.getSource();
String textd = (String)combo.getSelectedItem();
}
});
setTitle("Today is "+ texd+ "of "+ textm + "of " +texty);
}
public static void main(String[] args) {
new DateForm_Complete();
}
}