0

我希望能够从JFrame. 这是因为标题JFrame不是恒定的,而是取决于变量。

有没有办法将标题文本分配给字符串变量?

    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    if(super.checkifEmptyFields(jPanel3)==false){
        String LeaseName = jTextField2.getText().toLowerCase();
        String sld[]  =jDateChooser1.getDate().toString().split(" ");
        String startLeasingDate = sld[0]+","+sld[1]+","+sld[5].toLowerCase();
        String eld[]  =jDateChooser1.getDate().toString().split(" ");
        String EndLeasingDate = eld[0]+","+eld[1]+","+eld[5].toLowerCase();
        String leaseAmount = jTextField3.getText();
        String text = jTextField1.getText();
        int floor = Integer.parseInt(text.substring(6, 7));
        int flat = Integer.parseInt(text.substring(13));
        //String name NewLease2.getTitle;
    }
}

类名为 NewLease2 ,这是我想在用户按下按钮时执行的功能。

4

3 回答 3

6

你为什么不试试:

JFrame j = new JFrame("My Title here");
String whatTitle = j.getTitle();
于 2016-03-16T16:43:39.993 回答
1

在 的构造函数中JFrame,您可以设置一个私有实例变量并为其分配标题的值。

这将存储实例对象标题的原始值。

public class MyJFrame extends JFrame {
    private String originalTitle;

    public String getOriginalTitle() {
        return this.originalTitle;
    }

    public MyJFrame() {
        super();

        this.originalTitle = this.getTitle(); // Store a snapshot of the title.
    }
}
于 2016-03-16T16:44:20.663 回答
0

我得到了它。非常感谢您的帮助 Xoce 웃 Пepeúpa。我刚刚在我的功能中说了这个。

 private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    if(super.checkifEmptyFields(jPanel3)==false){
        String LeaseName = jTextField2.getText().toLowerCase();
        String sld[]  =jDateChooser1.getDate().toString().split(" ");
        String startLeasingDate = sld[0]+","+sld[1]+","+sld[5].toLowerCase();
        String eld[]  =jDateChooser1.getDate().toString().split(" ");
        String EndLeasingDate = eld[0]+","+eld[1]+","+eld[5].toLowerCase();
        String leaseAmount = jTextField3.getText();
        String text = jTextField1.getText();
        int floor = Integer.parseInt(text.substring(6, 7));
        int flat = Integer.parseInt(text.substring(13));
        JFrame j = this;
        String m =j.getTitle(); // << This is the bit that gets the title.
    }

现在它可以工作了:)

于 2016-03-16T17:27:53.543 回答