所以我制作了一个带有许多元素和按钮和事物的jframe,但我是新的使用NetBeans。创建Java应用程序后,创建了java,并在添加jframe时创建了另一个jframe.java。如何让主班打开,阅读和运行我的jframe.java?如果需要,我可以上传特定的代码。
预先感谢
要从另一类调用某个方法,您必须首先为该类创建一个新对象,例如:
Jframe frame = new Jframe();
frame.setVisible(true); //or whatever the method is in jframe.class
也许将实际的类名称从 jframe 重命名为 frameone 之类的东西。我听说命名课程与Java API中的课程相同。
或者,您可以将其全部放入一个类别,使用两种单独的方法或将其全部放在主要方法中。如果这无济于事,请在pastebin.org上粘贴确切的代码并给出一个链接。
查看此示例示例并了解如何设置框架可见
import java.awt.*;
import javax.swing.*;
public class exp{
public static void main(String args[]){
JFrame jf=new JFrame("This is JFrame");
JPanel h=new JPanel();
h.setSize(100,100);
h.add(new JButton("Button"));
h.add(new JLabel("this is JLabel"));
h.setBackground(Color.RED);
jf.add(h);
jf.pack();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
}
}
有用的链接
- 在Netbeans IDE设计摇摆GUI
- 创建带有摇摆的GUI(如@madprogrammer评论)
- 与Netbeans IDE一起学习摇摆
我是新手,但我得到了一个表格。woo hoo!
1) The project created my main function in japp1.java
2) I created a JFrame, file jfMain.java
3) While there was probably a way to reference it as it was, I didn't see how right away, so I moved it to a peer level with the japp1 file, both in a folder called japp1 which will cause them to get built together, having the same parent reference available.
src
japp1
japp1.java
jfMain.java
4) Then instead of creating a generic JFrame with a title, I created an instance of my class...
5) I gave it a size...
7) Then showed it...
public static void main(String[] args) {
// TODO code application logic here
JFrame frame = new japp1.jfMain();
frame.setPreferredSize(new Dimension(700, 500));
frame.pack();
frame.setVisible(true);
}
我已经在我的jframe中放了一些代码...从按钮上的mouseclick事件中显示了一个Messagedialog,并为某些Textfields设置了一些文本。
希望会有所帮助。