下面的方法扩展了一个JFrame,但是我需要一个swing文本框来接收double值并将它们存储在一个变量中.必须将文本框添加到容器中.
public class myClass extends JFrame{
Container container;
container = getContentPane();
//Item label
JLabel labelText = new JLabel();
...
labelText.setText ("Item:");
container.add( labelText );
//Item name: Textbox
//code to make a textbox, add it to the container, and store the value in a variable goes here
Run Code Online (Sandbox Code Playgroud) 我需要将以下数组放入JComboBox,然后在单击"提交"按钮时存储所选值.
listOfDepartments = new String[5];
listOfDepartments[0] = "Mens Clothing";
listOfDepartments[1] = "Womens Clothing";
listOfDepartments[2] = "Childrens Clothing";
listOfDepartments[3] = "Electronics";
listOfDepartments[4] = "Toys";
//Department: ComboBox that loads from array
// Store values
JButton buttonSubmit = new JButton();
buttonSubmit.setText("Submit");
container.add(buttonSubmit);
buttonSubmit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
//store value from combobox in a variable
}
});
Run Code Online (Sandbox Code Playgroud)