#javascript #java
Вопрос:
JFrame frame = new JFrame("Recipes");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(430, 100);
JPanel panel = new JPanel();
frame.add(panel);
JLabel lbl = new JLabel("Select time taken");
lbl.setVisible(true);
panel.add(lbl);
String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
final JComboBox<String> cb = new JComboBox<String>(choices);
cb.setVisible(true);
panel.add(cb);
JButton btn = new JButton("OK");
panel.add(btn);`
Я не знаю, что добавить после этого, я попытался добавить другую метку и выпадающие списки, но это не сработало
Ответ №1:
Убедитесь, что frame.setVisible(true);
это в последней строке
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame("Recipes");
//frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(430, 100);
JPanel panel = new JPanel();
frame.add(panel);
JLabel lbl = new JLabel("Select time taken");
lbl.setVisible(true);
panel.add(lbl);
String[] choices = { "10 MINS","15 MINS", "20 MINS","25 MINS","30 MINS"};
final JComboBox<String> cb = new JComboBox<String>(choices);
cb.setVisible(true);
panel.add(cb);
JButton btn = new JButton("OK");
panel.add(btn);
frame.setVisible(true);
}
}