我有一个包含所有代码的大型java文件,但它现在可以解决了,但是我遇到了一个我无法解决的错误。
这是gui.java代码:
public class gui extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
gui frame = new gui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
* @throws IOException
* @throws ClassNotFoundException
* @throws SQLException
*/
public gui() throws IOException, ClassNotFoundException, SQLException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 655, 420);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(1, 1));
setContentPane(contentPane);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
contentPane.add(tabbedPane, BorderLayout.CENTER);
setResizable(false);
//JOptionPane.showMessageDialog(contentPane, "Connecting to database. Ensure that there is no other process connecting to the database and this file is in the root directory of the DED project.");
Class.forName("org.h2.Driver");
String path = System.getProperty("user.dir");
String fullPath = path +"\\files\\db\\dedserver;AUTO_SERVER=TRUE";
Connection conn = DriverManager.getConnection("jdbc:h2://"+fullPath, "sa", "");
Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ImageBuilder builder = new ImageBuilder();
//home
JPanel home = new JPanel(new GridLayout());
Component hLabel = functions.makeTextPanel("<html><h1>DED GUI</h1><small>Made by Shivam Paw</small><br /> <br />To use this simple management tool navigate along the tabs above.<br /><br/><br />Report any bugs to shivampaw on the CoCDevForums.</html>");
home.add(hLabel);
tabbedPane.addTab("Home",home);
tabbedPane.setMnemonicAt(0,KeyEvent.VK_1);
ignPanel.main(tabbedPane,conn,stat);
serverPanel.main(tabbedPane, conn, stat);
playerList.main(tabbedPane, conn, stat);
api.main(tabbedPane, conn, stat, builder);
}
}
以下是我收到错误的代码。
api.java:
public static void main(JTabbedPane tabbedPane, Connection conn, Statement stat, ImageBuilder builder) throws SQLException, IOException {
JPanel editBase = new JPanel();
Component labe = functions.makeTextPanel("<html><center>You can edit the level of buildings on a players base using this tool. Credit to Sid3way for making the tool.<br /><br/>To get started enter a players ID below.</center></html>");
editBase.add(labe);
tabbedPane.addTab("Edit Base",editBase);
JPanel editidp = new JPanel();
editBase.add(editidp);
JTextField editID = new JTextField(3);
JButton editbtn = new JButton("Submit");
editidp.add(editID);
editidp.add(editbtn);
editbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String eid = editID.getText();
String query = "SELECT baseJson FROM homes WHERE id='"+eid+"'";
String msg;
ResultSet rs;
try {
rs = stat.executeQuery(query);
rs.next();
String jsonlol = rs.getString("basejson");
System.out.println(jsonlol);
msg = "Success!";
} catch (SQLException e) {
msg = "Error fetching players Json. Make sure you entered a valid ID.";
JOptionPane.showMessageDialog(editidp, msg);
}
if(msg == "Success!"){
JPanel desktop = new JPanel();
desktop.setLayout(new BoxLayout(desktop, BoxLayout.Y_AXIS));
/*ERROR HERE*/ setContentPane(desktop);
tabbedPane.setSize(new Dimension(654,420));
.....
错误是在倒数第二行。 setContentPane(dekstop);
我得到的错误是:
无法从JFrame类型
对静态方法setContentPane(Container)进行静态引用
我不知道如何解决这个问题,因为当我把它全部放在一个文件中时它运行正常。