Java 类型为orbital_app的方法setVisible(boolean)未定义
这是代码。我的主框架是orbital_应用程序,我希望当我点击JButton(按钮)时,数据被保存,当前窗口关闭,另一个窗口orbital_应用程序打开Java 类型为orbital_app的方法setVisible(boolean)未定义,java,eclipse,swing,Java,Eclipse,Swing,这是代码。我的主框架是orbital_应用程序,我希望当我点击JButton(按钮)时,数据被保存,当前窗口关闭,另一个窗口orbital_应用程序打开 public class signup_try { private JFrame frame; private JTextField txtname; private JTextField textusername; private JTextField txtpass; private JTextFi
public class signup_try {
private JFrame frame;
private JTextField txtname;
private JTextField textusername;
private JTextField txtpass;
private JTextField textmail;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
signup_try window = new signup_try();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public signup_try() {
initialize();
}
Connection connection=null;
/**
* Initialize the contents of the frame.
*/
private void initialize() {
connection=dbase.dBase();
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel label = new JLabel("Orbital");
label.setForeground(SystemColor.activeCaption);
label.setFont(new Font("Arial Black", Font.BOLD, 17));
label.setBounds(170, 11, 71, 25);
frame.getContentPane().add(label);
JLabel label_1 = new JLabel("Name:");
label_1.setForeground(SystemColor.activeCaption);
label_1.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_1.setBounds(21, 66, 46, 14);
frame.getContentPane().add(label_1);
txtname = new JTextField();
txtname.setColumns(10);
txtname.setBounds(102, 63, 200, 22);
frame.getContentPane().add(txtname);
textusername = new JTextField();
textusername.setColumns(10);
textusername.setBounds(102, 108, 200, 22);
frame.getContentPane().add(textusername);
txtpass = new JTextField();
txtpass.setColumns(10);
txtpass.setBounds(102, 150, 200, 22);
frame.getContentPane().add(txtpass);
textmail = new JTextField();
textmail.setColumns(10);
textmail.setBounds(102, 192, 200, 22);
frame.getContentPane().add(textmail);
JLabel label_2 = new JLabel("Username:");
label_2.setForeground(SystemColor.activeCaption);
label_2.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_2.setBounds(21, 111, 71, 14);
frame.getContentPane().add(label_2);
JLabel label_3 = new JLabel("Password:");
label_3.setForeground(SystemColor.activeCaption);
label_3.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_3.setBounds(21, 154, 71, 14);
frame.getContentPane().add(label_3);
JLabel label_4 = new JLabel("Email:");
label_4.setForeground(SystemColor.activeCaption);
label_4.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_4.setBounds(21, 196, 46, 14);
frame.getContentPane().add(label_4);
JButton button = new JButton("Sign Up");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query="insert into Users(Name, Username, Password, Email) values(?,?,?,?)";
PreparedStatement prepstat=connection.prepareStatement(query);
prepstat.setString(1, txtname.getText());
prepstat.setString(2, textusername.getText());
prepstat.setString(3, txtpass.getText());
prepstat.setString(4, textmail.getText());
prepstat.execute();
JOptionPane.showMessageDialog(null, "Data saved");
prepstat.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e);
}
方法setVisible(boolean)对于类型orbital\u app是未定义的。我该怎么做才能解决这个问题?在这里,我想关闭当前帧(注册尝试)并转到其他帧(轨道应用程序)。。setVisible带红色下划线,表示“未为orbital_app类型定义setVisible(布尔)方法”
}
sup_for.setVisible(true);
}
});
signup_btn.setFont(new Font("Arial", Font.PLAIN, 11));
signup_btn.setForeground(SystemColor.activeCaption);
signup_btn.setBounds(61, 133, 91, 23);
frame.getContentPane().add(signup_btn);
JButton signin_btn = new JButton("Sign In");
signin_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
signin_form log_for=new signin_form();
这里也是
log_for.setVisible(true);
}
});
signin_btn.setFont(new Font("Arial", Font.PLAIN, 11));
signin_btn.setForeground(SystemColor.activeCaption);
signin_btn.setBounds(285, 133, 91, 23);
frame.getContentPane().add(signin_btn);
JLabel notelbl = new JLabel("note: click Sign Up for new account or Sign In for existing account.");
notelbl.setHorizontalAlignment(SwingConstants.CENTER);
notelbl.setBounds(10, 199, 406, 25);
frame.getContentPane().add(notelbl);
}
}
您的代码似乎有一些问题 最重要的是:您的程序中有多个入口点。
应用程序中应该只有一个
publicstaticvoidmain(String[]args).
函数,即“程序启动”的位置
您得到的错误消息(方法setVisible(布尔值)对于类型orbital_app
)是未定义的)来自这样一个事实:类orbital_app
没有setVisible
函数,它的一个成员有,但这并不重要
您的orbital_应用程序
有一个属于JFrame
的私有成员,这使得您可以通过访问框架从orbital_应用程序
内部调用JFrames
方法,但您无法从外部访问它。看来你把继承权和所有权混为一谈了 如果您希望您的
orbital\u应用程序
类成为JFrame
,则需要从JFrame
继承。否则,您可以只实现希望为其他类公开的方法。或者您可以为私有
JFrame
对象创建一个getter,以便从外部访问它 我遇到了同样的问题,通过扩展JFrame
类解决了这个问题。
您的类应该扩展
JFrame
,因为setVisible()方法属于JFrame
类。您可能也应该显示orbital\u app
类。我假设您有一个类orbital\u app
?在你的问题中粘贴代码时,你确实需要正确设置代码格式。orbital_应用程序是另一个框架,我希望当我在当前框架中单击按钮时(注册尝试),它会将我带到该框架(orbital_应用程序)它不是一个JFrame,
它是一个orbital_应用程序
。它可能继承自JFrame
,但我们不能确定这一点,因为您没有显示该类。从你描述的错误来看,听起来好像不是。我已经发布了我的orbital_应用程序代码。。需要你的帮助伙计们我真的不知道问题是。。seVisible在orbital_应用程序中工作,但在signup_尝试中不工作虽然此链接可能会回答问题,但最好在此处包含答案的基本部分,并提供更多上下文,使用评论代替
sup_for.setVisible(true);
}
});
signup_btn.setFont(new Font("Arial", Font.PLAIN, 11));
signup_btn.setForeground(SystemColor.activeCaption);
signup_btn.setBounds(61, 133, 91, 23);
frame.getContentPane().add(signup_btn);
JButton signin_btn = new JButton("Sign In");
signin_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
signin_form log_for=new signin_form();
log_for.setVisible(true);
}
});
signin_btn.setFont(new Font("Arial", Font.PLAIN, 11));
signin_btn.setForeground(SystemColor.activeCaption);
signin_btn.setBounds(285, 133, 91, 23);
frame.getContentPane().add(signin_btn);
JLabel notelbl = new JLabel("note: click Sign Up for new account or Sign In for existing account.");
notelbl.setHorizontalAlignment(SwingConstants.CENTER);
notelbl.setBounds(10, 199, 406, 25);
frame.getContentPane().add(notelbl);
}
}