【发布时间】:2015-02-03 18:26:53
【问题描述】:
我面临的问题是,当我从 GUImain 类启动程序时,它可以正常工作,但是当我尝试从主类调用它时,什么也没有打开。
我从控制台得到的唯一消息是:
<terminated> Main [Java Application] /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java (5 Dec 2014 14:39:29)
这是我的主要课程代码:
public class Main
{
public static void main(String[] args)
{
int i = 0;
int t = 0;
int st = 0;
int h = 0;
Texts textObject = new Texts();
textObject.TextList();
Commands commandObject = new Commands();
commandObject.commands();
GUImain guiObject = new GUImain();
}
}
这是我的 GUImain 类
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTextPane;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
public class GUImain
{
private JFrame frame;
private JTextField textField;
//Launch the application.
public static void main(String[] args)
{
GUImain window = new GUImain();
window.frame.setVisible(true);
}
//Create the application.
public GUImain()
{
frame = new JFrame();
frame.setBounds(100, 100, 611, 471);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnInventory = new JButton("Inventory");
btnInventory.setBounds(514, 6, 91, 29);
frame.getContentPane().add(btnInventory);
JButton btnLoad = new JButton("Load");
btnLoad.setBounds(453, 6, 68, 29);
frame.getContentPane().add(btnLoad);
JButton btnSave = new JButton("Save");
btnSave.setBounds(404, 6, 54, 29);
frame.getContentPane().add(btnSave);
JButton btnOptions = new JButton("Options");
btnOptions.setBounds(335, 6, 76, 29);
frame.getContentPane().add(btnOptions);
JTextArea History = new JTextArea();
History.setText("lol");
History.setBounds(6, 6, 329, 343);
frame.getContentPane().add(History);
JButton btnEnter = new JButton("Enter");
btnEnter.setBounds(518, 404, 85, 39);
frame.getContentPane().add(btnEnter);
JScrollBar scrollBar = new JScrollBar();
scrollBar.setBounds(320, 6, 15, 338);
frame.getContentPane().add(scrollBar);
textField = new JTextField();
textField.setBounds(5, 410, 508, 28);
frame.getContentPane().add(textField);
textField.setColumns(10);
JTextArea textArea = new JTextArea();
textArea.setBounds(6, 357, 600, 42);
frame.getContentPane().add(textArea);
JLabel lblMapGoesHere = new JLabel("Map goes here");
lblMapGoesHere.setBounds(342, 37, 263, 312);
frame.getContentPane().add(lblMapGoesHere);
}
}
【问题讨论】:
-
我这样做了,它想出了这个。线程“main”java.lang.Error 中的异常:未解决的编译问题:方法 setVisible(boolean) 未在 Main.main(Main.java:17) 处为 GUImain 类型定义并且我在 GUImain 下设置了可见的GUImain 窗口 = new GUImain();
标签: java eclipse swing user-interface awt