我想改变jframe的标题。我想使用jMenu2中设置的值

时间:2016-05-02 10:05:15

标签: java swing jframe

public class HomeBrowse extends javax.swing.JFrame {


    /**
     * Creates new form HomeBrowse
     */
    public HomeBrowse() {
        initComponents();
        this.setSize(743, 528);
        this.setLocationRelativeTo(this);
        new NetInfo().say();
    }


public class NetInfo {

     public void say() {
       try {
       java.net.InetAddress i = java.net.InetAddress.getLocalHost();
       System.out.println(i.getHostName()); 
       jMenu2.setText(i.getHostName());
       }
       catch(Exception e){e.printStackTrace();}
     }
    }

public void Title() {

}

1 个答案:

答案 0 :(得分:1)

这是@MadProgrammer提出的解决方案

的解决方案
public class HomeBrowse extends javax.swing.JFrame {


    /**
     * Creates new form HomeBrowse
     */
    public HomeBrowse() {
        initComponents();
        this.setSize(743, 528);
        this.setLocationRelativeTo(this);
        setTitle(new NetInfo().say());
    }
}

public class NetInfo {

     public String say() {
       try {
           java.net.InetAddress i = java.net.InetAddress.getLocalHost();
           System.out.println(i.getHostName()); 
           jMenu2.setText(i.getHostName());
           return i.getHostName();
       }
       catch(Exception e){e.printStackTrace();}
       return null;
    }
}