1 Reply Latest reply: Jun 19, 2011 3:31 AM by EJP RSS

    How To load or display another java file class!!!

    869817
      Master I am newbie just starting to learn about java. I have probelm to make my project for exam. anybody can help me for solve this probe thanks i need that soon.

      I have 3 file's java and the probe is after login i want to go to another file to display.
      - frm_login
      - SMSCENTER
      -SMSCENTERservice

      This the source code:

      -frm_login.java
      _____________________________________________________________________________________________
      /* Indonesia
      * Ady Leo
      * Univeristas Budi Luhur
      */

      import javax.microedition.lcdui.Alert;
      import javax.microedition.lcdui.Command;
      import javax.microedition.lcdui.CommandListener;
      import javax.microedition.lcdui.Display;
      import javax.microedition.lcdui.Displayable;
      import javax.microedition.lcdui.Form;
      import javax.microedition.lcdui.TextBox;
      import javax.microedition.lcdui.TextField;
      import javax.microedition.lcdui.Ticker;
      import javax.microedition.midlet.*;
      import javax.microedition.lcdui.*;

      /**
      * @adyleo
      * Jakarta, Indonesian
      * contact me : leo.messi.it@gmail.com
      * open source , u can use this free, edit this free, dont forget to feedback to me
      */
      public class frm_login extends MIDlet implements CommandListener {

      private Display display;
      private Form formLogin;
      private TextField username;
      private TextField pass;
      private Ticker loginnews;
      private Command cmdKeluar;
      private Command cmdPilih;
      private Command cmdSch;

      private TextBox formAdmin;
      private Ticker ticker3;
      private Command cmdKeluar2;

      private SMSCENTER smscenter;


      private Alert alert;

      public frm_login() {
      display = Display.getDisplay(this);

      formLogin = new Form("LOGIN");
      username = new TextField("username", "", 50, TextField.ANY);
      pass = new TextField("password", "", 50, TextField.PASSWORD);
      loginnews = new Ticker("LOGIN USER");
      cmdKeluar = new Command("Keluar", Command.EXIT, 1);
      cmdPilih = new Command("Login", Command.OK, 2);
      cmdSch = new Command("Check", Command.OK, 3);
      formLogin.setTicker(loginnews);
      formLogin.append(username);
      formLogin.append(pass);
      formLogin.addCommand(cmdKeluar);
      formLogin.addCommand(cmdPilih);
      formLogin.setCommandListener(this);


      formAdmin = new TextBox("Welcome Halim", "Checks Your Flight Schedule", 40, TextField.ANY);
      ticker3 = new Ticker("WELCOME ABDUL HALIM ALHADY");
      formAdmin.setTicker(ticker3);
      formAdmin.addCommand(cmdKeluar);
      formAdmin.addCommand(cmdSch);
      formAdmin.setCommandListener(this);


      alert = new Alert("Error...!!!");
      alert.setTimeout(2500);
      }



                          
                          
      public void startApp() {
      display.setCurrent(formLogin);
      }

      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {
      }

      public void commandAction(Command c, Displayable d) {
      if (c == cmdKeluar) {
      destroyApp(false);
      notifyDestroyed();
      } else if( c == cmdPilih ) {
      String PESAN_ERROR = "";


      if (username.getString().trim().equals(""))
      PESAN_ERROR += " Username Atau Password Anda Salah ";
      if (pass.getString().trim().equals(""))
      PESAN_ERROR += " Silakan Coba Lagi!!! ";

      if (username.getString().trim().equals("messi") && pass.getString().trim().equals("lodewijk")) {
      display.setCurrent(formAdmin);


      } else {
      alert.setString(PESAN_ERROR);
      display.setCurrent(alert);
      }

      } else if ( c == cmdKeluar2 ){
      destroyApp(false);
      notifyDestroyed();

      //this the probe i want after i click the cmdSch will action to display another file java.. please help me
      } else if ( c == cmdSch ) {
           smscenter = new SMSCENTER();     
                     display.setCurrent(smscenter);
      }

      }



      }
      _____________________________________________________________________________________________


      -SMSCENTER.java
      _____________________________________________________________________________________________
      import javax.microedition.midlet.*;
      import javax.microedition.lcdui.*;

      public class SMSCENTER extends MIDlet implements CommandListener {

      Display display;
      SMSCENTERservice form;
      List list;
      Command cmExit;

      public SMSCENTER() {
      display = Display.getDisplay(this);
      }

      public void startApp() {
      list = new List("Sistem SMS Center", List.IMPLICIT);
      list.append("cek detil ", null);
      list.append("cek service ", null);
      list.append("cek surat", null);

      cmExit = new Command("Keluar", Command.EXIT, 1);

      list.addCommand(cmExit);
      list.setCommandListener(this);
      display.setCurrent(list);
      }

      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {//KOMPONEN 3
      }

      public void exitMIDlet() {
      destroyApp(false);
      notifyDestroyed();
      }

      public void commandAction(Command c, Displayable s) {//even dari tombol"nya
      if (c == List.SELECT_COMMAND) {

      switch (list.getSelectedIndex()) {
      case 0://jika menu yang pertama yg dipilih maka jalankan
      form = new SMSCENTERservice(this, display, 0);
      display.setCurrent(form);
      break;
      case 1:
      form = new SMSCENTERservice(this, display, 1);
      display.setCurrent(form);
      break;
      case 2:
      form = new SMSCENTERservice(this, display, 2);
      display.setCurrent(form);
      break;

      }

      } else if (c == cmExit) {
      exitMIDlet();
      }
      }
      }
      _____________________________________________________________________________________________


      -SMSCENTERservice.java
      _____________________________________________________________________________________________
      import java.io.IOException;
      import javax.microedition.lcdui.*;
      import javax.microedition.midlet.*;
      import javax.microedition.io.*;
      import java.util.*;

      public class SMSCENTERservice extends Form implements CommandListener, Runnable {

      private Display display;
      private Command cmdBack, cmdKirim;
      private SMSCENTER midlet;
      private TextField tfdetil,tfservice,tfsurat;

      private TextBox arti =new TextBox("","",1024,0);

      private Command cmdInputK = new Command("Input", Command.OK,1);
      private Command cmdKembaliK = new Command("Kembali", Command.BACK,2);

      private Alert alert,alert2,alert3,alert4;
      Object o;
      koneksi konek = new koneksi();
      String url = "";
      /////////////////////////////////////////////////////////////
      private int Index;

      private String messaage, address, pesan;
      private int index;
      private String port;

      public SMSCENTERservice(SMSCENTER midlet, Display display, int index) {
      super("Sistem SMS Gateway");
      this.display = display;
      this.midlet = midlet;
      this.index = index;
      switch (index) {
      case 0:
      append("cek detil");
      tfdetil = new TextField("DETIL SERVICE", "", 160, TextField.ANY);
      append(tfdetil);
      break;
      case 1:
           append("cek service ");
      tfservice = new TextField("SERVICE", "", 160, TextField.ANY);
                append(tfservice);
      break;
      case 2:
      append("cek surat");
      tfsurat = new TextField("SURAT SERVICE", "", 160, TextField.ANY);
      append(tfsurat);
      break;
                     
      }
      cmdBack = new Command("Kembali", Command.BACK, 1);
      addCommand(cmdBack);
      cmdKirim = new Command("Kirim", Command.OK, 1);
      addCommand(cmdKirim);
      setCommandListener(this);
      }

      public void commandAction(Command c, Displayable d) {
           o=c;
      if (c == cmdBack) {
      display.setCurrent(midlet.list);
      } else if (c == cmdKirim) {
      switch (index) {
      case 0:
      url = "http://localhost/service/proses.php?katakunci=detil_service&NomorDetil=" + tfdetil.getString();
      break;
      case 1:
      url = "http://localhost/service/proses.php?katakunci=service&NomorService=" + tfservice.getString();
      break;
      case 2:
      url = "http://localhost/service/proses.php?katakunci=surat_service&NomorSurat=" + tfsurat.getString();
      break;


      }

      }
      }

      public void run() {

      try {
           if(konek.downloadpage(url))
                {
                     arti.setString(konek.b.toString());
                     arti.addCommand(cmdInputK);
                     arti.addCommand(cmdKembaliK);
                     arti.setCommandListener(this);
                     display.setCurrent(arti);
                }     
      else
           {
                alert2 = new Alert("warning!", "Masukan kata lebih dahulu....",null, AlertType.INFO);
                display.setCurrent(alert2);
           }
      }

                     
      catch (IOException e)
      {    }
      }
      }
      _____________________________________________________________________________________________

      Sorry if i am posting not on the good way or worng places, anyway i hope someone can help me just in form login i am sutck...
      I am student just newbie for java programing.
      thnks a lot
        • 1. Re: How To load or display another java file class!!!
          EJP
          Please reformat that mess with {noformat}
          {noformat} tags. No-one can read it until you do.