English 中文(简体)
GUU Java Netbeans 多类
原标题:GUI Java Netbeans multiple classes

This is pretty elementary but I do not even know how to search anything for what I need. I have created a system that has a few classes and two projects that communicate with each other via sockets.

现在,我的目标是用设计师Netbeans(Netbeans)为这个系统创建一个图形用户界面(GUI),

  1. Should the GUI be my main class?
  2. If not, how do I send messages to my GUI class.
  3. When I try to do the following e.g JTextField.setText("PleaseHelp"); in the run method of the GUI I get an error saying : non-static variable JTextField cannot be referenced from a static context.

我知道我没有要求具体的东西,但我对如何寻找我需要的东西一无所知。我得到的只是关于如何制作简单的计算界面的辅导,因为只有一个类,即JFrame

问题回答
  1. It would be better if the GUI were a separate class, since a modularized application is more maintainable.
  2. As with all object oriented code, you need a reference to an instance of the GUI class.
  3. JTextField is a class and setText is not static. You need to reference the JTextField that you want to change.

基本上,它应该看起来是这样的:

GUI gui = new GUI(/*Parameters*/);
gui.getTextField().setText("PleaseHelp");

getTextFriel 是 GUI 类的一种方法( 添加到由 Netbeans GUI 设计师创建的类) :

public JTextField getTextField(){
  return /*TODO:  Enter text field name here*/;
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签