I have an issue using Java Swing. I have an easy assignment but I don't know how to create a new form using JOptionPane.
The assignment must start with JOptionPane and it must start with a dialog with two options: Settings and Close. Clicking Settings opens a new form, which has a label and a button.
The label contains the current time, which is displayed in the format HH:mm:ss and changes every second, the Timer activates immediately. The button is used to choose the color for the given label. There is a Stop button, which can stop the Timer and an additional button that can restart the watch.
Also, the label must change color between the chosen red and the default color.
When I run the app, the dialog box pops up, however I couldn't figure it out how to open another form after clicking the Settings button.
`
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Timer extends JFrame {
private JPanel MainPanel;
public Timer() {
this.setContentPane(MainPanel);
this.setTitle("Timer App");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
Timer frame = new Timer();
JButton settings = new JButton("Settings");
JButton close = new JButton("Close");
int option = JOptionPane.showOptionDialog(null, "Choose option", "Option dialog", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {"Settings", "Close"}, null);
}
}
`