抱歉,这是我的整个文件 . 我只是新手问这里 .
我在这里遇到了问题 . 而且我在这里和那里搜索过,我仍然不能让它发挥作用 .
我希望这里有人可以帮助我 .
谢谢!错误:C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:非法启动表达式public static void main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:非法启动表达式public static void main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:';' expected public static main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:error:')'expected public static void main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:表达式的非法开始public static void main(String args []){C: \ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:';'预期的public static void main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:error:非法启动表达式public static void main(String args []){C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ src \ RegistrationSource \ Login.java:181:错误:';' expected public static main(String args []){8 errors C:\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ nbproject \ build-impl.xml:930:执行此行时发生以下错误:C :\ Users \ John Mavrick De Leon \ Documents \ NetBeansProjects \ Registration \ nbproject \ build-impl.xml:270:编译失败;请参阅编译器错误输出以获取详细信
这里启动代码:
package RegistrationSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.*;
import static javax.swing.JOptionPane.INFORMATION_MESSAGE;
import java.awt.event.ActionEvent;
import static javax.swing.JOptionPane.PLAIN_MESSAGE;
public class Login extends javax.swing.JFrame {
public Login() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
tfusername = new javax.swing.JTextField();
pfpassword = new javax.swing.JPasswordField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
blogin = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
jSeparator2 = new javax.swing.JSeparator();
jSeparator3 = new javax.swing.JSeparator();
jSeparator4 = new javax.swing.JSeparator();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
jPanel1.setBackground(java.awt.SystemColor.activeCaption);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Welcome", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 36))); // NOI18N
jLabel1.setText("Username:");
jLabel2.setText("Password:");
blogin.setText("Login");
blogin.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
blogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bloginActionPerformed(evt);
}
});
jButton1.setText("Cancel");
jSeparator1.setForeground(new java.awt.Color(255, 255, 255));
jSeparator2.setForeground(new java.awt.Color(255, 255, 255));
jSeparator3.setForeground(new java.awt.Color(255, 255, 255));
jSeparator4.setForeground(new java.awt.Color(255, 255, 255));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(pfpassword)
.addComponent(tfusername, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(blogin, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(77, 77, 77)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addComponent(jSeparator2))))
.addContainerGap(46, Short.MAX_VALUE))
.addComponent(jSeparator3)
.addComponent(jSeparator4)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tfusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(38, 38, 38)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pfpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(blogin, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(400, 311));
setLocationRelativeTo(null);
}// </editor-fold>
private void bloginActionPerformed(java.awt.event.ActionEvent evt) {
String sql = "select *from administrators where Username=? and Password=?";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/localdatabase","root","");
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, tfusername.getText());
pst.setString(2, new String (pfpassword.getPassword()));
ResultSet rs = pst.executeQuery();
if (rs.next()){
JOptionPane.showMessageDialog(null, "Welcome " + tfusername.getText() + "!", "Successfull Log-in", JOptionPane.INFORMATION_MESSAGE);
dispose();
registrationform registration = new registrationform();
registration.setVisible(true);
}
else {
JOptionPane.showMessageDialog(null, "Invalid username or password! ", "Invalid", JOptionPane.ERROR_MESSAGE);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
/**
* @param args the command line arguments
*/
public static void main (String args []){
loading splash = new loading();
splash.setVisible(true);
try{
for (int i = 0 ; i<=100 ; i++)
{
Thread.sleep(40);
splash.loadnum.setText(Integer.toString(i)+"%");
splash.loadbar.setValue(i);
if (i == 100){
splash.setVisible(false);
JOptionPane.showMessageDialog(null, "STUDENT RECORD SYSTEM", "S.Y. 2018 - 2019", PLAIN_MESSAGE);
}
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton blogin;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JSeparator jSeparator4;
private javax.swing.JPasswordField pfpassword;
private javax.swing.JTextField tfusername;
// End of variables declaration
}
1 回答
好的 . 我会尽力帮助你,不仅仅是你的问题,还有你编码风格的东西 .
我会发布你的代码并评论我的解释 .
如果您只是复制此代码,它应该工作 . 不过,我建议阅读我的评论 .
我将总结你的错误和我的风格建议:
变量在类声明下声明
你不明白导入东西的目的 . 我建议你玩简单的东西来理解它 .
你可以使用一个lambda,这是更好的 .
你的 class 名称没有改正,因为这会弄乱你的代码 . 你应该自己纠正它 .
Now your main mistake: You simply forgot to close a curly bracket.
如果您不关心我的其他建议和改进,您可以忽略我写的所有内容并关闭方法“bloginActionPerformed”的大括号 . 这应该工作 .
玩得开心 .