你添加JFrame这个组件了么?import那几行该不会是你手敲上去的吧???
检查项目的构建路径:首先确保项目的构建路径中包含了正确的类库。在Eclipse中,可以通过右键单击项目,选择"Properties",然后在"Java Build Path"选项卡下查看是否有缺失的类库。如果有缺失的类库,可以点击"Add Library"按钮来添加。
检查JDK版本:确保项目使用的是正确的JDK版本。在Eclipse中,可以通过右键单击项目,选择"Properties",然后在"Java Compiler"选项卡下设置合适的JDK版本。
检查导入语句:确保导入语句正确无误。在Eclipse中,可以使用快捷键"Ctrl+Shift+O"来自动导入所需的类。
【相关推荐】
1)定义元素
public class mainframe extends JFrame {
private JPanel contentPane;
public static usertype usertype;
public static Object userobject;
private JDesktopPane desktopPane;
...
2)注销原有的样式
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// mainframe frame = new mainframe();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
3)
public mainframe(usertype usertype,Object userObject) {
this.usertype=usertype;
this.userobject=userObject;
...
setLocationRelativeTo(null);
....
4)给修改密码添加一个监听事件
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
editpassword(ae);
}
});
5)给退出系统添加一个监听事件
menuItem_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(JOptionPane.showConfirmDialog(mainframe.this, "确定要退出吗?")==JOptionPane.OK_OPTION){
System.exit(0);
}
}
});
6)给添加班级添加一个监听事件
menuItem_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// //addclassframe addclassframe=new addclassframe();
// addclassframe.setVisible(true);
// desktopPane.add(addclassframe);
}
});
7)定义 editpassword
protected void editpassword(ActionEvent ae) {
// TODO Auto-generated method stub
editpasswordframe editpasswordframe = new editpasswordframe();
editpasswordframe.setVisible(true);
desktopPane.add(editpasswordframe);
}