我想用可移植的GUI编写一个java代码(即独立于IDE)。使用Netbeans我可以设计一个带有调色板的表单,但是如果我将生成的代码复制到一个空白文件中并尝试在shell中使用javac
进行编译,并尝试使用java
运行它会产生错误。这是一个shell(Windows cmd)和我的java代码:
public class test extends javax.swing.JFrame {
public test() {
initComponents();
}
private void initComponents() {
jButton3 = new javax.swing.JButton();
jScrollBar1 = new javax.swing.JScrollBar();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("test");
jButton3.setText("Cancel");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(160, 160, 160)
.add(jButton3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 161, Short.MAX_VALUE)
.add(jScrollBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(91, 91, 91))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(142, 142, 142)
.add(jButton3))
.add(layout.createSequentialGroup()
.add(28, 28, 28)
.add(jScrollBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 192, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(154, Short.MAX_VALUE))
);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new test().setVisible(true);
}
});
}
private javax.swing.JButton jButton3;
private javax.swing.JScrollBar jScrollBar1;
}
这是我在运行程序时遇到的错误: