我希望能够从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,这是我想在用户按下按钮时执行的功能。
答案 0 :(得分:6)
为什么不尝试:
JFrame j = new JFrame("My Title here");
String whatTitle = j.getTitle();
答案 1 :(得分: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.
}
}
答案 2 :(得分: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.
}
现在它有效:)