문제

The following method extends a JFrame, but I need a swing textbox inside it to receive double values and store them in a variable. the textbox must be added to the container.

    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
도움이 되었습니까?

해결책

Use a JTextField:

 JTextField field = new JTextField(10);
 container.add(field, BorderLayout.SOUTH);

To get the value of the field, do Double.parseDouble(field.getText()).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top