我是 Java 的菜鸟,正在学习尝试了解 OOP。
我正在尝试整合课程并通过secondwindow.form2('null')
上班。
我不知道如何将变量传递给其他类。
任何帮助将不胜感激!
public class helloworld {
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
JFrame window = new JFrame("Hello world test");
window.setVisible(true);
window.setSize(500,500);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JOptionPane.showMessageDialog(window, "do NOT click 'OK'");
String word = JOptionPane.showInputDialog(window,"Enter a sentence");
int characters =word.length();
JOptionPane.showMessageDialog(window, characters);
NewDialouge secondwindow = new NewDialouge();
secondwindow.form2('null');
}
});
}
}
import javax.swing.JOptionPane;
public class NewDialouge {
public void form2(String spoon){
JOptionPane.showMessageDialog(spoon, "works.");
}
}