我的GUI运行时如何更新JTextField?

时间:2014-03-08 01:19:44

标签: java swing user-interface mouselistener

所以这是带有文本字段的类

public class SeatInformation extends JPanel{


 public static byte section = 0;
 public static int price = 0;
 public static char row = 0;
 public static byte number = 0;

public SeatInformation(String title){


    setLayout(new GridLayout(5,5)); 
     setLocation(500,20);
     setSize(100, 50); 



     //Section Label and TextField
    JLabel SectionLabel = new JLabel("Section:");
    SectionLabel.setVisible(true);
    add(SectionLabel); 

    JTextField Section = new JTextField(""+section);
    Section.setVisible(true);
    add(Section); 

这是我的代码,用于调用字段中的更改。

if(Stadium.getSeat(r,c).getSection() == 1){

                final byte s = Stadium.getSeat(r,c).getSection();
                final int p = Stadium.getSeat(r, c).getPrice();
                final char ro = Stadium.getSeat(r, c).getRow();
                final byte n = Stadium.getSeat(r, c).getNumber();


            re.addMouseListener(new MouseAdapter() { 
                public void mouseEntered(MouseEvent e){ 
                    SeatInformation.section = s;

                } 
                }); 

我不知道如何更新我的“SeatInformation”类中的所有值,所有建议都表示赞赏。

1 个答案:

答案 0 :(得分:2)

您必须在类的属性中保存JTextField的实例并调用setText()