How to autopress button in another Java app?

My mainapp should automatically press a "login" or "yes" button from another application.
In my mainapp I have:
private Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit = toolkit.addAWTEventListener(new LookForLoginOrYes, AWTEvent.WINDOW_EVENT_MASK);
public static class LookForLoginOrYes implements AWTEventListener {
   public void eventDispatched (AWTEvent event) {
      System.out.println("in LookFor..."+event.toString()); // this line is printed out!
      WindowEvent windowEvent = (WindowEvent) event;
      if (event.getID() == WindowEvent.WINDOW_OPENED) {
         System.out.println("LFA: WindowEvent.WINDOW_OPENED"); // this line is never printed
         Window window = windowEvent.getWindow();
         if (window instanceof Frame) {
            System.out.println("LFA: " + ((Frame) window).getTitle()); // never printed
}line with event.toString() displays that my mainapp has no focus anymore of has focus (for this I replaced WINDOW_EVENT_MASK with ~0L).
Clicking on the titlebar or so of the second app (with the 'yes' button) nothing happens.
Security settings?

The Robot class ties into the native interface, but has no concept of the application's components. Therefore, the only way the Robot class could perform this task is if a) you teach it to recognize the button from a screenshot of the desktop or b) you guarantee that the button is in a specific location. The Robot class is the only system-independent way to do this if your applications run in different JVMs. This is because each JVM is pretty much a seperate computer and, beyond network connections, file pipes, etc., each has no concept of the other's existence.
Are you able to modify both applications' source? If so, I would recommend you handle your situation this way:
public class AppOne extends JFrame
    public AppOne(...)
        JButton button = new JButton("That Button You Want To Press");
        button.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                thatButtonWasPressed();
    public void thatButtonWasPressed()
        ... // button-press code
    public static void main(String arg[])
        AppOne app = new AppOne(...);
        app.setLocationRelativeTo(null);
        app.setVisible(true);
public class AppTwo extends JFrame
    public AppTwo(AppOne other_app, ...)
        ... // at the appropriate point, call "other_app.thatButtonWasPressed()"
    public static void main(String arg[])
        AppOne app_one = new AppOne(...);
        AppTwo app_two = new AppTwo(app_one, ...);
        app_one.setLocationRelativeTo(null);
        app_one.setVisible(true);
        app_two.setLocationRelativeTo(null);
        app_two.setVisible(true);
}In this example, the button is not actually being pressed, but the same effect is generated. I recommend this approach because it cuts out a lot of potential interference. Why deal with the user interface if you don't have to? What you seem to want (and correct me if I'm wrong) is for the application to perform a specific operation on your request. The fact that this operation happens to also occur when a user presses a specific button is irrelevant.
Is there some reason you need the Swing/AWT system to actually think the button has been pressed? If you can't modify the source code of the one application, that would make sense.

Similar Messages

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to run a makefile from java app?

    Hi,
    I want to run a make command the first time my java swing application is run. The makefile is in a directory that the application is using for input files. Do I need to write a script to house the make command or is there another way to run make?
    Thanks

    Thanks for that but I'm not actually trying to build a makefile for my java app - I just want to be able to run one that is going to generate a bunch of html files for my application to access. The make command works great from the command line but I can't just put a directory followed by "make html" in a string and run it using runtime.exec in my application.

  • How to disable buttons when another button is clicked

    I have an application with 5 buttons that each play or pause
    different movieclips. How can I prevent other buttons from playing
    different movieclips when a movieclip is already playing.

    I looked in the help and found an example actionscript. I
    changed the button instance names to the button names in my app. I
    put the actionscript on frame 1 that holds the movieclip being
    played. Here it is
    mycase3_btn = true;
    mycase1_btn = false;
    mycase2_btn = false;
    //button code
    // the following function will not get called
    // because myBtn2_btn.enabled was set to false
    mycase1_btn.onRelease = function() {
    trace( "you clicked : " + this._name );
    mycase2_btn.onRelease = function() {
    trace( "you clicked : " + this._name );
    mycase3_btn.onRelease = function() {
    trace( "you clicked : " + this._name );
    It doesn't disable the other 2 buttons. As may be obvious I
    am new to all but the simplest actionscripts. What am I doing
    wrong?
    thank you for your time!

  • How to connect to mysql from java app

    hi
    please say the procedure for connecting to mysql database from java app.
    .) what should i give in environmental variables
    .)where can i find the driver class for the mysql
    .) syntax of the url
    eg:- DM.getConnection("jdbc:mysql:..............what comes here..............");

    You can also get connections from a DataSource. Simple example:
                MysqlDataSource msds = new MysqlDataSource();
                msds.setUrl("jdbc:mysql://127.0.0.1:3306/dbdame");
                msds.setUser("user");
                msds.setPassword("pass");
                Connection c = msds.getConnection();Explore your options and be sure to consider connection pooling.

  • How do I convert my GUI java app to be an applet or display it on a webpage

    I have created a loan calculator program in netbeans, I got the application to run fine but now I want to add it into a html page.
    I'm just looking for a place to start, I just don't know where to go from here, I want to know if I can actually convert my app with a few changes to an applet or if any one can point me to a forum of similar interest or tutorials that explain what I'm looking for.
    I don't even know what i'm looking for except i want this program to run on a webpage.
    Or is there a way to run my .jar file on a webpage??
    My teacher has not taught us anything on this matter except the below code suggestions on converting and my program is more extensive than her examples for converting. This is what she briefly described on this subject.
    1.To convert an application to an applet the main differences are: import java.awt.Graphics; import javax.swing.JApplet; import javax.swing.JOptionPane;
         Extend JApplet Replace main with public void init() method
    Output with public void paint( Graphics g ) method
    2. Remove calls to setSize, setTitle, pack, and any window listener calls, e.g., setDefaultCloseOperation. Compile the program---if something doesn't compile just comment it out for now.
    3. Create a simple web page with the following body.
    <applet CODE="__________.class" WIDTH="300" HEIGHT="300"
    archive="http://www.cs.duke.edu/courses/fall01/cps108/resources/joggle.jar">
    Your browser does not support applets </applet>
    I understand those steps for a simple program like hello world but not my current app
    Heres my code on the 2 extend off my first GUI of the Loan Application
    public class AnalysisGUI extends GUI {
        /** Creates new form AnalysisGUI */
        public AnalysisGUI(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }//end constructor
        private DecimalFormat currency = new DecimalFormat("0.00");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            analysisjButton = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            writejTextArea = new javax.swing.JTextArea();
            clearTextAreajButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            analysisjButton.setText("Analysis");
            analysisjButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    analysisjButtonActionPerformed(evt);
            writejTextArea.setColumns(20);
            writejTextArea.setRows(5);
            jScrollPane1.setViewportView(writejTextArea);
            clearTextAreajButton.setText("Clear Analysis Output");
            clearTextAreajButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearTextAreajButtonActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(analysisjButton)
                        .addComponent(clearTextAreajButton))
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 433, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(86, 86, 86))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(306, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(analysisjButton)
                            .addGap(84, 84, 84)
                            .addComponent(clearTextAreajButton)
                            .addGap(113, 113, 113))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(22, 22, 22))))
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-700)/2, (screenSize.height-627)/2, 700, 627);
        }// </editor-fold>
        private void analysisjButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
            // TODO add your handling code here:   
            //importing values for FOR loop of 13 pyaments a years
            ir13 = super.rate;
            balance13 = super.balance;
            time13 = super.time;
            payment13 = MortgageCalculator.CalculatePayment(ir13, balance13, time13, PayperYear13);           
            interest13 = round((balance13 * (ir13/PayperYear13)));                   
            principle13 = round(payment13 - interest13);
            //set up for 12 pyaments a year
            balance = super.balance;          
            ir = super.rate;
            time = super.time;         
            payment = super.payment;
            interest = round((balance * (ir/PayperYear12)));
            principle = round(payment - interest);
            //set up for 24 payments a year   
            balance24 = super.balance;          
            ir24 = super.rate;
            time24 = super.time;         
            payment24 = super.payment/2;
            interest24 = round((balance24 * (ir/PayperYear24)));
            principle24 = round(payment24 - interest24);
            //set up for 26 payemnts a years
            ir26 = super.rate;
            balance26 = super.balance;
            time26 = super.time;
            payment26 = MortgageCalculator.CalculatePayment(ir26, balance26, time26, PayperYear26);           
            interest26 = round((balance26 * (ir26/PayperYear26)));                   
            principle26 = round(payment26 - interest26);
         double totalPrinciple = 0;              //set to zero
         double totalInterest = 0;          //set to zero       
         for( int n = 0; n < time; n++)     //check Year of Loan
                totalPrinciple = 0;          //reset to zero for totaling Year n totals
                totalInterest = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 12 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments
                for(int i = 1; i <= PayperYear12; i++ )
                //Calculate applied amounts for chart to be printed
                interest = round((balance * ir)/PayperYear12);
                principle = round(payment - interest);
                balance = round(balance - principle);
                //total year end amounts
                totalPrinciple = totalPrinciple + principle;
                totalInterest = totalInterest + interest;
                writejTextArea.append("Payment " + i + " $" + currency.format(principle) + "     " +
                    currency.format(interest) + "      $" +
                    currency.format(balance)+"\n");     
                }//end for 12 payments per year
                //print 12 payments Totals          
                int yr = n + 1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 12 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");     
                //Start 13 PAYMENTS A YEAR TABLE
                double totalPrinciple13 = 0;          //reset to zero for totaling Year n totals
                double totalInterest13 = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 13 Payments Per Year-----\n");   
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly 13 payments           
                for(int j = 1; j <= PayperYear13; j++ )
                //Calculate applied amounts for chart to be printed
                interest13 = round((balance13 * ir13)/PayperYear13);
                principle13 = round(payment13 - interest13);
                balance13 = round(balance13 - principle13);
                //total year end amounts
                totalPrinciple13 = totalPrinciple13 + principle13;
                totalInterest13 = totalInterest13 + interest13;
                //System.out.printf("\n%-10s %-10s %-10s %-10s %-10s", n + 1 , i + 1,Principle, Interest, Balance);
                //System.out.printf("\n%-10s %-10s %-10.2f %-10.2f %-10.2f", n + 1 , i + 1,round(principle), round(interest), balance);
                writejTextArea.append("Payment " + j + " $" + currency.format(principle13) + "     " +
                    currency.format(interest13) + "      $" +
                    currency.format(balance13)+"\n");         
                }//end for 13 payments per year
                //Print totals for 13 payments a year          
                yr = n + 1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 13 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple13));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest13));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance13)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");             
                //Start 24 PAYMENTS A YEAR TABLE
                double totalPrinciple24 = 0;          //reset to zero for totaling Year n totals
                double totalInterest24 = 0;          //reset to zero for totaling Year n totals
                writejTextArea.append("-----Based on 24 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments
                for(int i = 1; i <= PayperYear24; i++ )
                //Calculate applied amounts for chart to be printed
                interest24 = round((balance24 * ir24)/PayperYear24);
                principle24 = round(payment24 - interest24);
                balance24 = round(balance24 - principle24);
                //total year end amounts
                totalPrinciple = totalPrinciple + principle24;
                totalInterest = totalInterest + interest24;
                writejTextArea.append("Payment " + i + " $" + currency.format(principle24) + "     " +
                    currency.format(interest24) + "      $" +
                    currency.format(balance24)+"\n"); 
                }//end for 24 payments per year
                //print 24 payments Totals
                yr = n +1;
                writejTextArea.append("\n---Year " + yr + " Totals Based on 24 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple24));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest24));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance24)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");                        
                //Start 26 PAYMENTS A YEAR TABLE
                double totalPrinciple26 = 0;//reset to zero for totaling Year n totals
                double totalInterest26 = 0;     //reset to zero for totaling Year n totals
                writejTextArea.append("------Based on 26 Payments Per Year-----\n");
                writejTextArea.append("          "+"          "+"Principle" + "    " +
                    "Interest"+ "    "+
                    "Balance"+"\n");            
                //loops through the monthly payments 26 times
                for(int i = 1; i <= PayperYear26; i++ )
                //Calculate applied amounts for chart to be printed
                interest26 = round((balance26 * ir24)/PayperYear26);
                principle26 = round(payment26 - interest26);
                balance26 = round(balance26 - principle26);
                totalPrinciple = totalPrinciple + principle26;
                totalInterest = totalInterest + interest26;
                writejTextArea.append("Payment " + i + "  $" + currency.format(principle26) + "     " +
                    currency.format(interest26) + "      $" +
                    currency.format(balance26)+"\n");
                }//end for 26 payments per year           
                yr = n + 1;
                //prints 26 payments yearly totals
                writejTextArea.append("\n---Year " + yr + " Totals Based on 26 Payments Per Year---");
                writejTextArea.append("\nYear Total Principle: $" + currency.format(totalPrinciple26));
                writejTextArea.append("\nYear Total Interest: $" + currency.format(totalInterest26));
                writejTextArea.append("\nRemaining Balance: $" + currency.format(balance26)+"\n");
                writejTextArea.append("\n-------------------------------------------------------\n");                
            }//end for years of the loan
        private void clearTextAreajButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            //clear analysis field
            writejTextArea.setText("");
        public static double round(double r)//round to cents method
              return Math.ceil(r*100)/100;
         }//end round  
        /**HI micha what a long progam
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    AnalysisGUI dialog = new AnalysisGUI(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                    dialog.setVisible(true);
            });//end announymous
        }//end main mehtod
        //12 year declared varialbes
        //private double balance;   
        private double principle;
        private double ir;
        private double interest;
        private double PayperYear12 = 12;
        //Variables for 13 payments a years
        private int PayperYear13 = 13;
        private double balance13;
        private double principle13;
        private double ir13;
        private double interest13;
        private double payment13;
        private double time13;
        //Varialbes for 24 payments a year
        private int PayperYear24 = 24;
        private double balance24;
        private double principle24;
        private double ir24;
        private double interest24;
        private double payment24;
        private double time24;
        //Varialbes for 24 payments a year
        private int PayperYear26 = 26;
        private double balance26;
        private double principle26;
        private double ir26;
        private double interest26;
        private double payment26;
        private double time26;
        // Variables declaration - do not modify
        private javax.swing.JButton analysisjButton;
        private javax.swing.JButton clearTextAreajButton;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea writejTextArea;

    Your original program extends "GUI" which appears to extend JFrame (correct me if I'm wrong). If so, the first thing you should do would be to re-write this so that it extends JPanel which shouldn't be that hard to do (at least it's not hard to do if you know a little Swing -- but I worry about someone coming into this from the netbeans-generated code world). Purists will tell you to not even extend this, to have your main GUI class hold an instance of JPanel instead, and this would work fine too, as long as one way or another, the main GUI program can produce your application displayed on a JPanel on demand.
    If you've done this correctly, then using your JPanel in a JFrame is trivial: in a main method create a JFrame, and then simply add your JPanel to the JFrame's contentPane and display it. Likewise using your JPanel in a JApplet is just as trivial as you'd do essentially the same thing: add your JPanel to the JApplet's contentPane, but this time do it in the JApplet's init method.

  • How to remove Button from Flex Mobile app actionbar with AS3?

    How exactly would i remove a Button from the actionBar "actionContent" in a flex mobile app?
    I tried these:
        this.stage.removeChild(menu_btn);
        this.removeChild(menu_btn);
        stage.removeChild(menu_btn);
        this.stage.removeElement(menu_btn);
        this.removeElement(menu_btn);
        stage.removeElement(menu_btn);
    I'm not having any luck with those. Im guessing where it is located in the actioncontent isn't considered the stage. Any ideas?
        <s:actionContent>
                            <s:CalloutButton id="menu_btn" icon="@Embed('assets/images/menu/menu_btn.png')" visible="false">
                                      <s:VGroup>
                                      <s:Button id="btn_one" label="Button" />
                                      </s:VGroup>
                            </s:CalloutButton>
                  </s:actionContent>
    The actionContent is setup like that, I know like with most mxml stuff I could give it an ID to reference it but im not sure how how to give the action content an id number `<s:actionContent id="testID">` does not work. So how can i access this to remove it? making it invisible isn't cutting it i need to actually remove it.

    Does this do what you are looking for?
    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
        <s:actionContent>
            <s:Button id="excess" label="excess" />
            <s:Button label="remove" click="this.navigator.actionBar.actionGroup.removeElement(excess);" />
        </s:actionContent>
    </s:View>

  • Transmit API: How to send video to another running app.

    Hi,
    I'm not a programmer so excuse my ignorance.
    Just trying to scope a project.
    We'd like to get a live video output from Premiere to use in another app.
    The idea is to use a video stream from Premiere as a texture map for a navigable 3d model.
    It's for doing really rough 3d previs work.
    We have an existing version of the 3d previs app that does the same thing with imported quicktime movies.
    But our coder has not used the Premiere SDK before.
    Wondering if we can use Transmit somehow... to treat our app as an external monitor.
    Any pointers on how to go about this... or better still... is there anyone out there who might be up for helping us on this (low-budget but paid) project?
    Many thanks
    Marcus Lyall

    Hi Marcus,
    Yes, the Mercury Transmit API sounds like way to go for you.  I'd recommend starting from the sample project "Transmitter".  Build it into the PPro plug-ins folder (as described in the SDK Guide.pdf documentation, chapter 1, "How To Build the SDK Projects").  Your developer can set breakpoints in the transmit sample code and run a debug session with PPro, to observe how transmit plug-ins are called, and what kind of information they are passed.  It sounds like you won't working with audio, so you can just turn that off in the sample.  Chapter 9 of the SDK Guide has much more info on concepts in the transmit API.
    Regards,
    Zac

  • How to user netbean to follow java app logic flow

    I imported a j2se application (about 60 classes) into the netbean IDE, I was able to compile and run it. I am new to this program and would like to use netbean to execute this app step by step to follow the logic flow of the program and to understand this program. How do I do that?
    Thanks

    You don't NEED an IDE such as JBuilder, but it does make things a little easier.
    What I'm guessing you have is a bunch of .class files and you want to turn it into something compact and executable, right? The best thing to do is create an executable .jar file. Jar is a type of compressed archive similar to Zips.
    In the JDK, there is a program called jar.exe which you can use to pack your classes into a JAR file. To run a jar file, in the command prompt, or a batch file, simple write "java -jar MyApp.jar". You can also run a Jar file just by doubleclicking it by setting: java.exe "-jar" "%L" in the file types menu in explorer.
    If you have something like JBuilder, you can make it automatically create the Jar file when you build your app.

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

    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 : [email protected]
    * 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

    Please reformat that mess with {noformat}{noformat} tags. No-one can read it until you do.                                                                                                                                                                                                                                                                                                                                   

  • How to set button to open an .app file?

    Hi i would like to know if it is possible to make a button in flash that when clicked on opens an external .app file, I am very new to flash but I am desperately seeking a way that would allow me to directly launch an app from the button. Ideally I am looking for a screen with two buttons, one would show a video and the other would launch an .app (processing export). It is really important I find a way to do this bcause it is for presentation.
    I have searched all over the internet for a really long time I am beginning to think it is not possible.
    Please is there any way at all? If flash can open pdfs and links or even send emails surely it can launch applications?
    I am using a Mac and adobe flash cs6, desperately needing some help!
    Thanks

    Under File>Publishing Options the default Publishing Option is generally
    Flash.swf/HTML-Wrapper for the WEB
    Under other Formats you will find at the bottom: Mac Projektor, if you choose that option, Flash will "bake" the Flash Player
    into your app, meaning even people who haven`t installed Flash can view the file.
    Disadvantage: your .app file is considerably bigger than the .swf would be and it can`t be viewed inside a browser. It must directly run on the users machine.

  • Compiling application (with several sub-packages) from another java app

    Hi,
    I'm writing my own build tool and need to be able to compile an external application (pulled from cvs, subversion, ...) from within this build tool.
    Probably I need to use com.sun.tools.javac.Main.compile ?
    But how do I pass classpath, output dir, etc to this class and how can I make it compile all files in all (sub)packages of the given folder ?
    thanks for any help.

    Never mind my previous post, I found a solution to the "the input line is too long" problem:
    Putting all the files in a temporary file and then providing that file as the source to compile, like this:
    javac -g:none -cp <classpath> -d classes @sourcefiles.txtwhere sourcefiles.txt is the name of the temporary file that contains the names of the source files (note the "@"-prefix)
    For some reason, this is not mentioned/documented in the java docs (at least not in my docs)
    Ok, so everything is compiling now, but I have one problem remaining:
    For each "module" that I compile (the application I use for my tests consists of several "modules", i.e. subpackages), I get an error stating that "The system cannot find the path specified"
    This seems obvious, because it is trying to write a file <package-name>\classes\<package-name>\<classname>.class
    But why is it trying to write that file ?
    -> Is this a known bug or something ?
    Let me explain a little more...
    For each compilation I do using the com.sun.tools.javac.Main.compile() method, it is giving this error.
    Everything is compiling correctly, but it seems it is trying to write an extra class file to a wrong path.
    Until now, it was always the first file in the row that gave the problem.
    Example:
    ** module 1:
    sources/com/example/module1/class1.java
    sources/com/example/module1/class2.java
    sources/com/example/module1/class3.java
    sources/com/example/module1/sub1/subclass1.java
    sources/com/example/module1/sub1/subclass2.java
    sources/com/example/module1/sub1/subclass3.java
    ** module 2:
    sources/com/example/module2/class1.java
    sources/com/example/module2/class2.java
    sources/com/example/module2/class3.java
    sources/com/example/module2/sub1/subclass1.java
    sources/com/example/module2/sub1/subclass2.java
    sources/com/example/module2/sub1/subclass3.java
    => My application will compile module 1, do some other things with it and the module 2 and again do some other things with it.
    The result would be:
    Application started.
    Loading configuration: OK
    Compiling sources for module module1: E:\temp\_User_\project\packaging\workingdir\source\com/example/module1\class1.java:12: error while writing com.example.module1.class1: com\example\module1\classes\com\example\module1\class1.class (The system cannot find the path specified)public class class1 extends Thread {
           ^
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -deprecation for details.
    1 error
    OK
    Note: Contents of my classes directory for module1:
    classes/com/example/module1/class1.class
    classes/com/example/module1/class2.class
    classes/com/example/module1/class3.class
    classes/com/example/module1/sub1/subclass1.class
    classes/com/example/module1/sub1/subclass2.class
    classes/com/example/module1/sub1/subclass3.class
    => all class files are correctly compiled
    Compiling sources for module module2: E:\temp\_User_\project\packaging\workingdir\source\com/example/module2\class1.java:12: error while writing com.example.module2.class1: com\example\module2\classes\com\example\module2\class1.class (The system cannot find the path specified)public class class1 extends Thread {
           ^
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -deprecation for details.
    1 error
    OK
    Application finished without errors.
    Note: Contents of my classes directory for module2:
    classes/com/example/module2/class1.class
    classes/com/example/module2/class2.class
    classes/com/example/module2/class3.class
    classes/com/example/module2/sub1/subclass1.class
    classes/com/example/module2/sub1/subclass2.class
    classes/com/example/module2/sub1/subclass3.class
    So, as you can see everything compiles as expected, but an error message is displayed related to each first file that is compiled.
    ==> Is this a known issue ?
    ==> What can I do about it ?
    Suggestions welcome

  • How to implement secure Licencing for Java Apps?

    Hi
    I'm already thinking some months about this topic. I serached the web, some books and magazines, i asked quite a lot of people - but in the end, there seems to be no really satisfying answer.
    My main question is: what can i do to protect the software i wrote? The problem is, where ever i start, i end with open questions.....
    I may start delivering a custom licence key with my software that contains information i.e. about who may run it and for how long. To check integrity i sign the licences key (with a digest) and ckeck the integrity in the application. Like this, i could make sure, that the software runs only with a valid licence.
    But two new problem araise - if the licence key is given to the web, everyone will be able to run the software. Second, i have to implement a methode to check the digest, so i have to deliver the key with the software and like this, the key could just be used to generate new licence files. Third, i hav to protect my code, since anyone could recompile it, he could check the algorithms i use to check the digest and even worse, he just could disable the codeblock that checks the licence.
    So i use an obfuscator to scramble my code, and to get the most out of this technique, i use a controlflow obfuscator. This adds some security, but still the code can be decompiled but wouldn't be too easy to understand. For making it even a little bit harder to read, i will "distribute" the licence digest check over some different classes.
    But still the first two problems remain. So i think about encrypting the licence file. To make that secure, i would use a public/private key encryption since if i use a secret key encryption i would have to deliver the key with the software and anyone could use it to generate new encrypted licene files. The problem with the public/private key is, that i should deliver a public key with the software that is only capable of decrypting, but not of encrypting. Like this, i can implement a decryption methode in the software that can decrypt the licence file and read all requiered licence data but the user is not able to generate a new licence file because he has the read-only key. Obvisouly there is no such private/public key technique that allows one key to be decrypt only and the other to be encrypt and decrypt (or at least encrypt only). Algorithms like PGP have a public key that allows encryption only and a private key that allows decryption only.
    I could go on presenting some more ideas i found to "protect" software/licence but the all come to the same point where they leave a lot of other open questions.
    I wonder what you all out there do to protect your software, what kind of technique you use for licencing implementation. I would be very glad to read what problem you face reagarding this topics and maybe how you solved it or what your conclusion was.
    Greetings
    josh

    >
    yes, absolutely. That's the point. Try to make it hard
    to get the software some other way. So it's easer to
    get the software by buying it.
    Nope.
    - There are those who steal it just to steal it. They don't use it.
    - There are those who steal it because the price is too extreme. If your income for the year is measured as only several thousand dollars you are not going to be able to buy a package that costs a thousand dollars or more.
    - There are those who steal it because the preceived benifit is less than the cost. For instance, at least in the past, MS software cost at least three times as much in some european companies compared to the exchange rate.
    - Finally there are those who steal simply because they don't want to pay for it.
    As far as I am concerned the last category is the only relevant one. And that is far smaller than any software theft estimates that the software industry regularly claims.
    >
    >>
    Here is an example of someone who thinks that their
    work is good enough and valuable enough to stand on
    its own...http://www.fileviewer.com/.
    And I liked it enough that at one company I hadthem
    purchase a site license. And I like it enough thatI
    still remember the company five years after thelast
    time I needed the product.that's fine and it would be very nice if everybody
    would be like you. But that's not the case and you
    even may not be sure if not someone in that company
    took a copy of the software and the licence and now is
    using it for free are even gave it in the "public
    domain". Woulnd't that be sad if the company would
    have to close down someday because just a few people
    are paying for it. Even if it is such a smart
    product?There was a clothing chain that closed down because they claimed that, even after installing anti-theft devices, they were still losing too much money from shop lifters.
    If that is the case why do all of the other companies still exist?
    If your product is good then people will buy it. The successes for that are abundant. The only success stories for copy protection schemes are for the copies that sell those schemes.
    >
    i wonder if you close your door when you leava your
    appartment. I mean, what's wrong with protecting a
    code? It's just the same as protecting the money you
    earn, the furnish in your appartment, ...
    Sorry, when I buy a product then I expect to be able to use it.
    With your analogy I would have to use a code that you provided everytime I wanted to get into and out of my apartment.
    So for any comments, ideas, ... on how to addsome
    more protection i'm very thankfull.You search for "obfuscator".yes, as i wrote in the first posting, i know about
    obfuscator, i'm using it, but it's just very poor
    protection. That's why I'm looking for a smart concept
    to gain a little bit more protection.And if you search for that term in these forums, and read the lengthy posts, you might find some ideas. Which is why I suggested it. (And you might understand why the alternatives are not used.)

  • How to get RTP protocol to Java app?

    Hi,
    I need to work with RTP streams, but I've got problem that I cannot use rtp protocol - if I want to create a new url, MalformedURLexception is raised, here is sample code:
    java.net.URL url;
    try{
         url = new java.net.URL("rtp://www.someweb.cz:8080");
    catch(Exception e){
         System.out.println("Cannot create url - "+e);
    }http and ftp work fine. Can someone explain me what is wrong? JMF is installed on my system...

    MalformedURLexception is raised/*Because your URL is not of proper format*/
    //New mlr should be
    ("rtp://www.someweb.cz:8080//video//1")                    ///Becuse it's windoz //
    !("rtp://www.someweb.cz:8080)
    hmm, damn,
    i hope it works.
    kiss                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

  • Avaya(Non-java app) integration with ADF

    Hi,
    We have a desktop application Avaya (non-Java) & want to integrate it with ADF. Currently we do it by passing parameters in HTTP URL. If the user clicks on a button in non-java app, it should:
    (1) open search page of an ADF application and execute search.
    (2) if the ADF application is already open, the button on Avaya app should execute search with partial page refresh. However, the whole page is being refreshed.
    Can you please guide, how to do this with partial page refresh? , as the No 1 is almost achieved.
    Thanks,
    NC

    Hi Shay,
    Below Options were tried for integration. Please have a look at them and suggest if there is any other possible way to Integrate Avaya with ADF.
    1) Calling ADF application with URL parameters.
    Reasons to drop:
    Every time a URL is called the entire page will get rendered again taking some 2-3 seconds which is very critical to the application.
    ADF is capable of handling URL parameters without re-loading the whole page(http://oracamp.com/passing-parameters-adf-application-through-url). But we can't use this inbuilt way as we have many customized developments implemented in the page. This way directly works at AMImpl (at Model level) level. We want the events to be fired at View level. That is backing bean level.
    2) Avaya is capable of dealing with ActiveX (OCX). They sent me 2 DLLs which handles communication between web page and Avaya application. A simulator was also sent (bundle attached herewith). The steps to be carried out for testing are-
    Installation procedures:
    i. Register the DTLCRMINT.ocx file. Start->Run-> Type the command
    ii. regsvr32 <ocx file location>
    iii. Register the DTLINTCMP.ocx file. Start->Run-> Type the command
    iv. regsvr32 <ocx file location>
    v. Double click on the Clinet.exe it would open up a windows application with a Textbox and Command button. Put In the data which needs to be sent.
    vi. Open the CRM Page.html. On opening the OCX would be loaded by default.
    vii. Now clicking the Send Data button on the client application, whatever information is there in the Client Text Box would be sent to the web page.
    viii. From CRM side, the application needs to use the OCX provided, and must wait for the event. On receiving the event the data that is retrieved as a part of the event can be parsed to update the text box and click on the search button.
    Reasons to drop:
    It works fine with basic HTML page. But once integrated with ADF page as an inline frame it doesn't work. We tried to embed the OCX object inside <verbatim> tags, but was not successful. The event fired by ActiveX object is triggered at client side by VBScript function. Avaya's ActiveXs seem to be only working with VBScript according to my understanding. So there was no way for ADF to capture VBScript events.
    ADF is capable of javascript up to some extent. To do a critical application like this, my feeling is javascript is never a good option.
    3) To use a text file. Avaya writes, ADF application reads.
    Reasons to drop:
    ADF can read the text files with normal java IO methods. But only the server directories are visible. So, Avaya has to write the information in the server file. With using a parameter like user name, ADF application can read the file in regular time intervals (with using poll feature) and get relevant information and automatically run the search.
    Initially the idea was to do this at client side. But since this is a web application, file reading at client side is next to impossible. Again when one side is reading and the other side is writing, file access violations may occur.
    4) Another option is if Avaya can offer the value in a web service, the ADF application can get it.
    Reasons to drop:
    There may occur a latency as well as Avaya says they can't offer web services.
    5) The ideal solution is, the ADF application's front end control's IDs can be provided. If the Avaya system is capable of accessing or getting hold of DOM and pushing the value to the controls and clicking the button; things would become pretty straight forward. JMeter works like this in testing J2EE applications.
    Any Recommendations how can it be done .
    Thanks.

Maybe you are looking for