Original Post
heey all,
I'm trying to create a Java+php program that allows users to login, go to different pages and do some stuff. I chose java instead of html for this since I wanted to do more then just create static webpages, if I want, I can add more graphical stuff and since I wanted to try a php/java project.
My idea was, for the java side, to create a JApplet and let this be loaded by the only html page. For the different (java-)pages I created multiple JPannels with some UI on it. If a user succesfully logs in, the loginpanel will be destroyed and the Overview page(another (java-)page) will be shown.
I can get a connection to the server fine, let php log the user in and get the login info(login succes, wrong password, no user and errors) back. But the problem lies in destroying the loginpanel and showing the next page. I have no idea how to do this.
Can somebody help me with this. I am fairly new to java but not to php and programming in general. Below is some of the code I use.
thanks in advance,
assainator
my code
main.java
I'm trying to create a Java+php program that allows users to login, go to different pages and do some stuff. I chose java instead of html for this since I wanted to do more then just create static webpages, if I want, I can add more graphical stuff and since I wanted to try a php/java project.
My idea was, for the java side, to create a JApplet and let this be loaded by the only html page. For the different (java-)pages I created multiple JPannels with some UI on it. If a user succesfully logs in, the loginpanel will be destroyed and the Overview page(another (java-)page) will be shown.
I can get a connection to the server fine, let php log the user in and get the login info(login succes, wrong password, no user and errors) back. But the problem lies in destroying the loginpanel and showing the next page. I have no idea how to do this.
Can somebody help me with this. I am fairly new to java but not to php and programming in general. Below is some of the code I use.
thanks in advance,
assainator
my code
main.java
import javax.swing.*;public class Main extends JApplet{ //data LoginPanel lp; //Called when this applet is loaded into the browser. @Override public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { //create a LoginPanel class lp = new LoginPanel(); add(lp); } }); } catch (Exception e) { System.err.println("Couldn't initialize GUI"); } }}import javax.swing.*;import java.io.*;import java.net.*;public class LoginPanel extends javax.swing.JPanel{ //data Main m; //a class boolean LoginSucces; /** Creates new form LoginPanel */ public LoginPanel() { initComponents(); this.setSize(800, 600); LoginSucces = false; } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //setup connection try { //server connect code //get server response BufferedReader serverReader = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream())); String response = ""; String serverResponse = ""; while((response = serverReader.readLine()) != null) { serverResponse = serverResponse + response; } //close the in stream serverReader.close(); //responses from the server String GO = "GO"; String NO_USER = "NO_USER"; String INVALID_PW = "INVALID_PW"; //if the response was "GO" this means it was a valid login if(serverResponse.trim().equals(GO)) { LoginSucces = true; this.setVisible(false); } //if the response was else if(serverResponse.trim().equals(NO_USER)) { JOptionPane.showMessageDialog(this, "User does not exist"); jTextField1.setText(""); jTextField1.requestFocus(); jPasswordField1.setText(""); } else if(serverResponse.trim().equals(INVALID_PW)) { JOptionPane.showMessageDialog(this, "User\Password combination not valid"); jPasswordField1.setText(""); jPasswordField1.requestFocus(); } else ServerResponseLabel.setText(serverResponse); //show the response } catch(Exception ex) { ServerResponseLabel.setText(ex.getMessage()); } } // Variables declaration - do not modify private javax.swing.JLabel ServerResponseLabel; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JTextField jTextField1; // End of variables declaration }