如果您的课程扩展了Jframe,请使用
this.setTitle(newTitle.getText());
如果没有,并且包含一个名为myframe的Jframe,则使用
myframe.setTitle(newTitle.getText());
现在,您已经发布了程序,很明显,您只需要一个JTextField即可获得新标题。这些更改将达到目的:
JTextField poolLengthText, poolWidthText, poolDepthText, poolVolumeText, hotTub, hotTubLengthText, hotTubWidthText, hotTubDepthText, hotTubVolumeText, temp, results, newTitle;
和:
public void createOptions() { options = new JPanel(); options.setLayout(null); JLabel labelOptions = new JLabel("Change Company Name:"); labelOptions.setBounds(120, 10, 150, 20); options.add(labelOptions); newTitle = new JTextField("Some Title"); newTitle.setBounds(80, 40, 225, 20); options.add(newTitle);// myTitle = new JTextField("My Title...");// myTitle.setBounds(80, 40, 225, 20);// myTitle.add(labelOptions); JButton newName = new JButton("Set New Name"); newName.setBounds(60, 80, 150, 20); newName.addActionListener(this); options.add(newName); JButton Exit = new JButton("Exit"); Exit.setBounds(250, 80, 80, 20); Exit.addActionListener(this); options.add(Exit); }和:
private void New_Name(){ this.setTitle(newTitle.getText());}


