JOptionPane in JApplet

If I display a JOptionPane through a JApplet, it has "Applet Window" written on its status bar.
How do I get rid of the "Applet window" status bar on the message boxes using JOptionPane?
From practical experience of applets on the net I'm not used to
seeing this text at the bottom - this doesn't happen in the "real world"
does it?

Yes, that is a part of the Java platform security mechanism - a feature that warns users so that they do not mistake it for a native application so they do not type in sensitive info which is sent back to the host.
Getting rid of it is possible but you will need to know about security and permissions - if you grant your applet the correct AWT permission, that warning banner will disappear (for all windows that applet spawns).
A good place to start is http://java.sun.com/docs/books/tutorial/security1.2/tour1/index.html.
And a little bit of history: every version of the SDK watered down the warning a bit (the top one is SDK 1.0):
"Untrusted Java Applet Window"
"Unauthenticated Java Applet Window"
"Warning: Java Applet Window"
And now it is: "Java Applet Window"

Similar Messages

  • 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.

  • JOptionPane not painting correctly in JApplet.

    Having a JOptionPane painting problem in my JApplet.
    applet has a JFrame, that is the "main" container.
    Main frame is already shown. USer clicks a button, and all I'm trying to do is show a simple JOptionPane.
    SPecifically trying to call JOptionPane.showMessageDialog(null, "test message");
    Note the button that generates the event, is on a Panel, within the JFrame.
    I've tried just about everyting I can think of. SwingUtilites.invokeLater ... setting the null to JFrame, applet... and just about everything else...
    JOptionPane does pop up, but the background of the Pane never paints correctly... I've used 1.3.1_04, and 1.4 .. plugins...
    Now at a lost... Read all the newsgroups... and forums..
    But I'm missing somehting?
    Thanks in advace...
    EB.

    check what is in ur paint(Graphic g) method. if it does nothing, remove the paint(Graphic g) method. if it has some codes, double check ur codes.

  • How can I change my JApplet into a JApplication?

    I am working with a JApplet and am finding that some of my code only works in applications.
    So being new to this, I am clueless as to how to change my Applet into an Application. I understand the difference in definition between the two, but when it comes to looking at Applet Code and Application Code, I am not able to see a difference. (Other than an Applet stating "Applet")
    So, that being said how can I change my code so that it runs as an application and not an applet? Here is my current layout code
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    // Creating the main class
    public class test extends JApplet implements ActionListener
         // Defining of format information
         JLabel heading = new JLabel("McBride Financial Services Mortgage Calculator");
         Font newFontOne = new Font("TimesRoman", Font.BOLD, 20);
         Font newFontTwo = new Font("TimesRoman", Font.ITALIC, 16);
         Font newFontThree = new Font("TimesRoman", Font.BOLD, 16);
         Font newFontFour = new Font("TimesRoman", Font.BOLD, 14);
         JButton calculate = new JButton("Calculate");
         JButton exitButton = new JButton("Quit");
         JButton clearButton = new JButton("Clear");
         JLabel instructions = new JLabel("Please Enter the Principal Amount Below");
         JLabel instructions2 = new JLabel("and Select a Loan Type from the Menu");
         // Declaration of variables
         private double principalAmount;
         private JLabel principalLabel = new JLabel("Principal Amount");
         private NumberFormat principalFormat;
         private JTextField enterPrincipal = new JTextField(10);
         private double finalPayment;
         private JLabel monthlyPaymentLabel = new JLabel("  Monthly Payment    \t         Interest Paid    \t \t            Loan Balance");
         private NumberFormat finalPaymentFormat;
         private JTextField displayMonthlyPayment = new JTextField(10);
         private JTextField displayInterestPaid = new JTextField(10);
         private JTextField displayBalance = new JTextField(10);
         // Creation of the String of arrays for the ComboBox
         String [] list = {"7 Years @ 5.35%", "15 Years @ 5.50%", "30 Years @ 5.75%"};
         JComboBox selections = new JComboBox(list);
         // Creation of the textArea that will display the output
         private TextArea txtArea = new TextArea(5, 10);
         StringBuffer buff = null;
         // Initializing the interface
         public void init()
              // Creation of the panel design and fonts
              JPanel upper = new JPanel(new BorderLayout());
              JPanel middle = new JPanel(new BorderLayout());
              JPanel lower = new JPanel(new BorderLayout());
              JPanel areaOne = new JPanel(new BorderLayout());
              JPanel areaTwo = new JPanel(new BorderLayout());
              JPanel areaThree = new JPanel(new BorderLayout());
              JPanel areaFour = new JPanel(new BorderLayout());
              JPanel areaFive = new JPanel(new BorderLayout());
              JPanel areaSix = new JPanel(new BorderLayout());
              Container con = getContentPane();
              getContentPane().add(upper, BorderLayout.NORTH);
              getContentPane().add(middle, BorderLayout.CENTER);
              getContentPane().add(lower, BorderLayout.SOUTH);
              upper.add(areaOne, BorderLayout.NORTH);
              middle.add(areaTwo, BorderLayout.NORTH);
              middle.add(areaThree, BorderLayout.CENTER);
              middle.add(areaFour, BorderLayout.SOUTH);
              lower.add(areaFive, BorderLayout.NORTH);
              lower.add(areaSix, BorderLayout.SOUTH);
              heading.setFont(newFontOne);
              instructions.setFont(newFontTwo);
              instructions2.setFont(newFontTwo);
              principalLabel.setFont(newFontThree);
              monthlyPaymentLabel.setFont(newFontFour);
              displayInterestPaid.setFont(newFontFour);
              displayBalance.setFont(newFontFour);
              areaOne.add(heading, BorderLayout.NORTH);
              areaOne.add(instructions, BorderLayout.CENTER);
              areaOne.add(instructions2, BorderLayout.SOUTH);
              areaTwo.add(principalLabel, BorderLayout.WEST);
              areaTwo.add(enterPrincipal, BorderLayout.EAST);
              areaThree.add(selections, BorderLayout.NORTH);
              areaFour.add(calculate, BorderLayout.CENTER);
              areaFour.add(exitButton, BorderLayout.EAST);
              areaFour.add(clearButton, BorderLayout.WEST);
              areaFive.add(monthlyPaymentLabel, BorderLayout.CENTER);
              areaSix.add(txtArea, BorderLayout.CENTER);
              // Using the ActionListener to determine when each button is clicked
              calculate.addActionListener(this);
              exitButton.addActionListener(this);
              clearButton.addActionListener(this);
              enterPrincipal.requestFocus();
              selections.addActionListener(this);
         }

    baftos wrote:
    Here is one of the sites that explains the procedure:
    [http://leepoint.net/notes-java/deployment/applications_and_applets/70applets.html].
    But maybe you should try to fix the code that does not work as applet?
    Which one is it?
    >Here is one of the sites that explains the procedure:
    [http://leepoint.net/notes-java/deployment/applications_and_applets/70applets.html].
    But maybe you should try to fix the code that does not work as applet?
    Which one is it?
    The code that doesn't work in my applet is the exit button code
    else if (source == exitButton)
                        System.exit(1);
                   }I also can't get my program to properly validate input. When invalid input is entered and the user presses calculate, an error window should pop up. Unfortunately it isn't. I compile and run my applications/applets through TextPad. So when I try to test the error window by entering in invalid info, the applet itself shows nothing but the command prompt window pops up and lists errors from Java. Anyhow, here is the method I was told to use to fix it.
    private static boolean validate(JTextField in)
              String inText = in.getText();
              char[] charInput = inText.toCharArray();
              for(int i = 0; i < charInput.length; i++)
                   int asciiVal = (int)charInput;
              if((asciiVal >= 48 && asciiVal <= 57) || asciiVal == 46)
              else
                   JOptionPane.showMessageDialog(null, "Invalid Character, Please Use Numeric Values Only");
                   return false;
                   return true;
         }My Instructor told me to try the following, but I still can't get it to work.String content = textField.getText();
    if (content.length() != 0) {       
    try {          Integer.parseInt(content);  
    } catch (NumberFormatException nfe) {}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • JButtons in JToolbar don't work with JApplet- why?

    I made a JApplet which has a toolbar, populated with burrons that manipulate data from text files. The programs works perfectly when it is not a JApplet. However, once I converted it to a JApplet it does nothing. The code was exactly the same, but, pressing buttons does nothing when it is an applet. here is the complete code;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7    1 = 6...
                    public JButton getToolBarButton(String s)
                        String imgLoc = "TBar Icons/" +s +".gif";
                        java.net.URL imgURL = CSE.class.getResource(imgLoc);
                        JButton button = new JButton();
                        button.setActionCommand(s);
                        button.setToolTipText(s);
                        button.addActionListener(this);
                        if(imgURL != null)
                            button.setIcon(new ImageIcon(imgURL, s));
                        else
                            button.setText(s);
                            System.err.println("Couldn't find; " +imgLoc);
                        return button;
                        public CSE()
                                   // super("Test CSE");
                                    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    for(int x=0; x<materialNames.length; x++)
                                        materials = getToolBarButton(materialNames[x]);
                                        mainSelect.add(materials);
                                    //checkBoxes
                                    dataToShow.add(weeklySelect);
                                    dataToShow.add(dailySelect);
                                    weeklySelect.addItemListener(this);
                                    dailySelect.addItemListener(this);
                                    // sizes
                                    setSize(850, 850);
                                    //colors and fonts
                                    weeklyGraph.setBackground(new Color(250, 30, 40));
                                    dailyGraph.setBackground(new Color(100, 40, 200));
                                    //text Manip.
                                    prediction.setLineWrap(true);
                                    priceUpdate.setLineWrap(true);
                                    //scrolling
                                    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    //main splitpane config.
                                    mainConsoleBackdrop.setOneTouchExpandable(true);
                                    mainConsoleBackdrop.setResizeWeight(.85);
                                    //placement and Layout
                                    //GraphLayout
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(dailyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(weeklyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    dataOut.setRightComponent(predictionScroll);
                                    //consoleData layout
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalBuy);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalSell);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(buySell);
                                    finalPricesLay.add(finalPricesLabels);
                                    finalPricesLay.add(Box.createVerticalStrut(10));
                                    finalPricesLay.add(weeklySelect);
                                    finalPricesLay.add(dailySelect);
                                    finalPricesLay.add(priceUScroll);
                                    dataOut.setLeftComponent(finalPricesLay);
                                    mainConsoleBackdrop.setTopComponent(graphs);
                                    mainConsoleBackdrop.setBottomComponent(dataOut);
                                    getContentPane().add(mainConsoleBackdrop);
                                    getContentPane().add(mainSelect, BorderLayout.NORTH);
                                    //visibility
                                   // CSEFrame.setVisible(true);
                                    //return(CSEFrame);
                                        public void actionPerformed(ActionEvent e)
                                            getMonth();
                                            inputS = e.getActionCommand();
                                            FileReader newRead = null;
                                                    try {
                                                           newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
                                                           proceed = true;
                                                        catch(FileNotFoundException f)
                                                           System.out.println("File not found");
                                                           proceed = false;
                                          if(proceed)
                                          BufferedReader bufferedReader = new BufferedReader(newRead);
                                          scanner  = new Scanner(bufferedReader);
                                          scanner.useDelimiter("\n");
                                         //starts daily analysis
                                          getPrice(scanner);
                                        //starts weekly analysis
                                          weekly(inputS);
                                    public void itemStateChanged(ItemEvent e)
                                        if(weeklySelect.isSelected())
                                        priceUpdateWeekly.setText("");
                                        finalPricesLay.remove(priceUScroll);
                                        finalPricesLay.add(priceUScrollW);
                                        finalPrices.updateUI();
                                        else
                                            priceUpdate.setText("");
                                            finalPricesLay.remove(priceUScrollW);
                                            finalPricesLay.add(priceUScroll);
                                            finalPrices.updateUI();
                                    public void weekly(String inputS)
                                        weekly = true;
                                        for(int x = 0; x < 7; x++)
                                           dateToUse(month, day, year, (x+1));
                                            try
                                                    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
                                                    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
                                                    week[x] = new Scanner(weeklyBuffer);
                                                    week[x].useDelimiter("\n");
                                                    getPrice(week[x]);
                                             catch(FileNotFoundException f)
                                                JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
                                        weekly = false;
                                        dateReset();
                                    public void getPrice(Scanner scanner)
                                        while(scanner.hasNextLine())
                                            //puts into string the next scan token
                                            String s = scanner.next();
                                            //takes the scan toke above and puts it into an editable enviroment
                                            String [] data = s.split("\\s");
                                            for(position = 0; position < data.length; position++)
                                                        //Scanner test to make sure loop can finish, otherwise "no such line" error
                                                        if(scanner.hasNextLine()==false)
                                                        scanner.close();
                                                        break;
                                                           /*Starts data orignazation by reading from each perspective field
                                                            * 1 = day
                                                            * 2 = day of month
                                                            * 3 = month
                                                            * 4 = year
                                                           if(position == 0 && weekly == false)
                                                               String dayFromFile = data[position];
                                                                int dayNum = Integer.parseInt(dayFromFile);
                                                              priceUpdate.append(days[dayNum-1] +" ");
                                                           else if(position == 1  && weekly == false )
                                                              priceUpdate.append(data[position] + "/");
                                                           else if(position == 2 && weekly == false)
                                                              priceUpdate.append(data[position] + "/");
                                                            else if(position == 3 && weekly == false)
                                                                priceUpdate.append(data[position] +"\n");
                                                           //if it is in [buy] area, it prints and computes
                                                            else if(position == 7)
                                                                //obtains string for buy price and stores it, then prints it
                                                                String buy = data[position];
                                                            if(weekly == false)
                                                            priceUpdate.append("Buy: " +buy +"\n" );
                                                             //converts buy to string
                                                            currentBuyPrice = Integer.parseInt(buy);
                                                            //eliminates problems caused by no data from server- makes the price 0
                                                            if(currentBuyPrice < 0)
                                                                currentBuyPrice = 0;
                                                            //if it is greater it adds
                                                            if(currentBuyPrice > buyPrice)
                                                                     buyPrice += currentBuyPrice;
                                                            //if it is equal [there is no change] then it does nothing    
                                                            if(currentBuyPrice == buyPrice)
                                                                buyPrice +=0;
                                                            //if there is a drop, it subtracts
                                                               else
                                                                   buyPrice -= currentBuyPrice;
                                                            //if it is in [sell] area, it prints, and resets the position to zero because line is over
                                                            else if(position == 8)
                                                                //puts sell data into string and prints it
                                                                String sell = data[position];
                                                                if(weekly == false)
                                                                priceUpdate.append("Sell: " + sell +"\n");
                                                                //turns sell data into int.
                                                              currentSellPrice = Integer.valueOf(sell).intValue();;
                                                            //gets rid of problems caused by no data on server side- makes it 0 
                                                            if(currentSellPrice < 0)
                                                                currentSellPrice = 0;
                                                            //adds if there is an increase
                                                            if(currentSellPrice > sellPrice)
                                                                     sellPrice += currentSellPrice;
                                                            //does nothing if it is the same    
                                                            if(currentSellPrice == sellPrice)
                                                                sellPrice +=0;
                                                            //subtracts if there is drop
                                                               else
                                                                   sellPrice -= currentSellPrice;
                                                                //further protection against "No such line" and moves it down
                                                               if(scanner.hasNextLine() == true)
                                                                scanner.nextLine();
                                                                //if scanner is finished, prints out all lines
                                                               if(scanner.hasNextLine() == false && weekly == false)
                                                                finalBuy.setText("Net Buy Price Change: "+buyPrice);
                                                                finalSell.setText("Net Sell Price Change: " +sellPrice);
                                                                buyPrice = 0;
                                                                sellPrice = 0;
                                                                position = data.length;
                                                               else if(scanner.hasNextLine() == false && weekly == true)
                                                                   priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
                                                                   buyPrice = 0;
                                                                   sellPrice = 0;
                                                                   position = data.length;
                                                                   dayOfWeek++;
                                                                   if(dayOfWeek > 6)
                                                                   dayOfWeek = 0;
                                public void getMonth()
                                    for(int x=0; x < monthCheck.length; x++)
                                        if(month == monthCheck[x])
                                              monthS = (x+1);
                                              x = monthCheck.length;
                                 public void dateToUse(int month, int day, int year, int increment)
                                 //set day of source
                                  dayS = (day - increment);
                                //if day of source is less then O then we have moved to another month 
                                if(dayS <= 0)
                                        //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
                                        int incrementDay = increment - day;
                                        //decrements month
                                        monthS--;
                                        //if month is less then zero, then we have moved into another year and month has become 12
                                        if(monthS <= 0)
                                            yearS--;
                                            monthS = 12;
                                        //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
                                           if(month == 3)
                                               dayS = 28 - incrementDay;
                                           else if(month == 5 || month == 7)
                                               dayS = 29 - incrementDay;
                                           else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
                                               dayS = 31 - incrementDay;
                                            else
                                                dayS = 30 - incrementDay;
                               //resets the source date to the current date once data from the week has been reached
                                public void dateReset()
                                    dayS = day;
                                    monthS = month;
                                    yearS = year;
                     public void init()
                         //JFrame frame = new CSEFrameSet();
                        // this.setContentPane(CSEFrameSet());
                        CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }I have tried uploading it to a server, running it from appletviewer, and locally using the .HTML file. The GUI works fine, everything is there, however, pressing the buttons does nothing.
    Can you not use the Scanners and such with JApplets?
    Yes, the directories are good.
    EDIT EDIT EDIT; OK, it works with appletviewer, but still doesn't work when it is published.
    Message wa

    I can't seem to edit the post anymore, here it is again;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7 1 = 6...
    public JButton getToolBarButton(String s)
    String imgLoc = "TBar Icons/" +s +".gif";
    java.net.URL imgURL = CSE.class.getResource(imgLoc);
    JButton button = new JButton();
    button.setActionCommand(s);
    button.setToolTipText(s);
    button.addActionListener(this);
    if(imgURL != null)
    button.setIcon(new ImageIcon(imgURL, s));
    else
    button.setText(s);
    System.err.println("Couldn't find; " +imgLoc);
    return button;
    public CSE()
    // super("Test CSE");
    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for(int x=0; x<materialNames.length; x++)
    materials = getToolBarButton(materialNames[x]);
    mainSelect.add(materials);
    //checkBoxes
    dataToShow.add(weeklySelect);
    dataToShow.add(dailySelect);
    weeklySelect.addItemListener(this);
    dailySelect.addItemListener(this);
    // sizes
    setSize(850, 850);
    //colors and fonts
    weeklyGraph.setBackground(new Color(250, 30, 40));
    dailyGraph.setBackground(new Color(100, 40, 200));
    //text Manip.
    prediction.setLineWrap(true);
    priceUpdate.setLineWrap(true);
    //scrolling
    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    //main splitpane config.
    mainConsoleBackdrop.setOneTouchExpandable(true);
    mainConsoleBackdrop.setResizeWeight(.85);
    //placement and Layout
    //GraphLayout
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(dailyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(weeklyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    dataOut.setRightComponent(predictionScroll);
    //consoleData layout
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalBuy);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalSell);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(buySell);
    finalPricesLay.add(finalPricesLabels);
    finalPricesLay.add(Box.createVerticalStrut(10));
    finalPricesLay.add(weeklySelect);
    finalPricesLay.add(dailySelect);
    finalPricesLay.add(priceUScroll);
    dataOut.setLeftComponent(finalPricesLay);
    mainConsoleBackdrop.setTopComponent(graphs);
    mainConsoleBackdrop.setBottomComponent(dataOut);
    getContentPane().add(mainConsoleBackdrop);
    getContentPane().add(mainSelect, BorderLayout.NORTH);
    //visibility
    // CSEFrame.setVisible(true);
    //return(CSEFrame);
    public void actionPerformed(ActionEvent e)
    getMonth();
    inputS = e.getActionCommand();
    FileReader newRead = null;
    try {
    newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
    proceed = true;
    catch(FileNotFoundException f)
    System.out.println("File not found");
    proceed = false;
    if(proceed)
    BufferedReader bufferedReader = new BufferedReader(newRead);
    scanner = new Scanner(bufferedReader);
    scanner.useDelimiter("\n");
    //starts daily analysis
    getPrice(scanner);
    //starts weekly analysis
    weekly(inputS);
    public void itemStateChanged(ItemEvent e)
    if(weeklySelect.isSelected())
    priceUpdateWeekly.setText("");
    finalPricesLay.remove(priceUScroll);
    finalPricesLay.add(priceUScrollW);
    finalPrices.updateUI();
    else
    priceUpdate.setText("");
    finalPricesLay.remove(priceUScrollW);
    finalPricesLay.add(priceUScroll);
    finalPrices.updateUI();
    public void weekly(String inputS)
    weekly = true;
    for(int x = 0; x >< 7; x++)
    dateToUse(month, day, year, (x+1));
    try
    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
    week[x] = new Scanner(weeklyBuffer);
    week[x].useDelimiter("\n");
    getPrice(week[x]);
    catch(FileNotFoundException f)
    JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
    weekly = false;
    dateReset();
    public void getPrice(Scanner scanner)
    while(scanner.hasNextLine())
    //puts into string the next scan token
    String s = scanner.next();
    //takes the scan toke above and puts it into an editable enviroment
    String [] data = s.split("\\s");
    for(position = 0; position < data.length; position++)
    //Scanner test to make sure loop can finish, otherwise "no such line" error
    if(scanner.hasNextLine()==false)
    scanner.close();
    break;
    /*Starts data orignazation by reading from each perspective field
    * 1 = day
    * 2 = day of month
    * 3 = month
    * 4 = year
    if(position == 0 && weekly == false)
    String dayFromFile = data[position];
    int dayNum = Integer.parseInt(dayFromFile);
    priceUpdate.append(days[dayNum-1] +" ");
    else if(position == 1 && weekly == false )
    priceUpdate.append(data[position] + "/");
    else if(position == 2 && weekly == false)
    priceUpdate.append(data[position] + "/");
    else if(position == 3 && weekly == false)
    priceUpdate.append(data[position] +"\n");
    //if it is in [buy] area, it prints and computes
    else if(position == 7)
    //obtains string for buy price and stores it, then prints it
    String buy = data[position];
    if(weekly == false)
    priceUpdate.append("Buy: " +buy +"\n" );
    //converts buy to string
    currentBuyPrice = Integer.parseInt(buy);
    //eliminates problems caused by no data from server- makes the price 0
    if(currentBuyPrice < 0)
    currentBuyPrice = 0;
    //if it is greater it adds
    if(currentBuyPrice > buyPrice)
    buyPrice += currentBuyPrice;
    //if it is equal [there is no change] then it does nothing
    if(currentBuyPrice == buyPrice)
    buyPrice +=0;
    //if there is a drop, it subtracts
    else
    buyPrice -= currentBuyPrice;
    //if it is in [sell] area, it prints, and resets the position to zero because line is over
    else if(position == 8)
    //puts sell data into string and prints it
    String sell = data[position];
    if(weekly == false)
    priceUpdate.append("Sell: " + sell +"\n");
    //turns sell data into int.
    currentSellPrice = Integer.valueOf(sell).intValue();;
    //gets rid of problems caused by no data on server side- makes it 0
    if(currentSellPrice < 0)
    currentSellPrice = 0;
    //adds if there is an increase
    if(currentSellPrice > sellPrice)
    sellPrice += currentSellPrice;
    //does nothing if it is the same
    if(currentSellPrice == sellPrice)
    sellPrice +=0;
    //subtracts if there is drop
    else
    sellPrice -= currentSellPrice;
    //further protection against "No such line" and moves it down
    if(scanner.hasNextLine() == true)
    scanner.nextLine();
    //if scanner is finished, prints out all lines
    if(scanner.hasNextLine() == false && weekly == false)
    finalBuy.setText("Net Buy Price Change: "+buyPrice);
    finalSell.setText("Net Sell Price Change: " +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    else if(scanner.hasNextLine() == false && weekly == true)
    priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    dayOfWeek++;
    if(dayOfWeek > 6)
    dayOfWeek = 0;
    public void getMonth()
    for(int x=0; x < monthCheck.length; x++)
    if(month == monthCheck[x])
    monthS = (x+1);
    x = monthCheck.length;
    public void dateToUse(int month, int day, int year, int increment)
    //set day of source
    dayS = (day - increment);
    //if day of source is less then O then we have moved to another month
    if(dayS <= 0)
    //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
    int incrementDay = increment - day;
    //decrements month
    monthS--;
    //if month is less then zero, then we have moved into another year and month has become 12
    if(monthS <= 0)
    yearS--;
    monthS = 12;
    //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
    if(month == 3)
    dayS = 28 - incrementDay;
    else if(month == 5 || month == 7)
    dayS = 29 - incrementDay;
    else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
    dayS = 31 - incrementDay;
    else
    dayS = 30 - incrementDay;
    //resets the source date to the current date once data from the week has been reached
    public void dateReset()
    dayS = day;
    monthS = month;
    yearS = year;
    public void init()
    //JFrame frame = new CSEFrameSet();
    // this.setContentPane(CSEFrameSet());
    CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }Message was edited by:
    Cybergasm

  • Database access problem in JApplet

    Hi,
    I have a Swing application that accesses MS Access to store, query data. This app is running absolutely fine. I'm using Sun's ODBC-JDBC bridge driver and created a DSN in Windows for this.
    Now I have changed the main program (the main menu program) a bit, by coding "extends JApplet" etc. so that it can run as an Applet.
    Now, while I run this, I'm able to call programs, but there seems error while it's accessing MS Access tables.
    As applet is not executed from a Command Window, I'm not able to see the System.out.println () outputs. So, I don't have exact clue where is the error. (Though I know it's because of access to MS Access tables as I have coded JOptionPane for popping up a window for this).
    In this regard, I needed:
    1. A way to see the Console (or command window) or some way to see the outputs fom println () .
    2. What I can do so that the app can access MS Access?
    Any help is appreciated.
    Thanks in advance.
    Rajeev.

    Once again!
    You will probably need to sign your Applet jar file.
    http://java.sun.com/docs/books/tutorial/jar/sign/signing.html
    http://java.sun.com/developer/Books/javaprogramming/JAR/sign/signing.html

  • Fillrect to display multiple times on japplet - help!

    I am really having a hard time getting my program to work. The requirement is for a user to input the four requirements or parameters of the drawRect method class and to draw multiple rectangles in different coordinates on the screen.
    I have my code, it is working, but it is not putting the rectangles on different areas on the screen. It seems like it is not moving the coordinates when it goes through the loop.
    Here it is:
    import javax.swing.*;
    import java.awt.Graphics;
    public class fillRect extends JApplet {
    int num1, num2, num3;
    int num4, num5, num6;
    int num7, num8, num9;
    int num10, num11, num12;
    int num13, num14, num15, num16;
    int num17, num18, num19, num20;
    public void init()
    String input;
    int Xl, Yl, Width, Height;
    for ( int i = 1; i <= 1; i++ )
    String inputString; //string entered by the user
    //read from user as a string,
    //and convert type String to type int
    inputString = JOptionPane.showInputDialog("Please enter the upper left X-coordinate value:");
    Xl=Integer.parseInt( inputString );
    inputString = JOptionPane.showInputDialog("Please enter the upper left y-coordinate value:");
    Yl=Integer.parseInt( inputString );
    inputString = JOptionPane.showInputDialog("Please enter the width (non-negative):");
    Width = Integer.parseInt( inputString);
    inputString = JOptionPane.showInputDialog("Please enter the height (non-negative):");
    Height = Integer.parseInt( inputString );
    if ( Xl >= 1 && Yl <= 100 && Height <= 100 && Width <= 100 )
    switch ( i ) {
    case 1:
    num1 = Xl;
    num2 = Yl;
    num3 = Width;
    num4 = Height;
    break;
    case 2:
    num5 = Xl;
    num6 = Yl;
    num7 = Width;
    num8 = Height;
    break;
    case 3:
    num9 = Xl;
    num10 = Yl;
    num11 = Width;
    num12 = Height;
    break;
    case 4:
    num13 = Xl;
    num14 = Yl;
    num15 = Width;
    num16 = Height;
    break;
    case 5:
    num17 = Xl;
    num18 = Yl;
    num19 = Width;
    num20 = Height;
    break;
    else
    JOptionPane.showMessageDialog ( null, "Must be between 1 and 1000", "Error", JOptionPane.ERROR_MESSAGE );
    public void paint ( Graphics g) {
    int x, y = 0, value = 0, value1 = 0, value2 = 0, value3 = 0;
    for ( int i = 1; i <= 1; i++ ) {
    x = 5;
    switch ( i ) {
    case 1:
    value = num1;
    y = 50;
    value2 = num3;
    value3 = num4;
    break;
    case 2:
    value = num5;
    y = 60;
    value2 = num7;
    value3 = num8;
    break;
    case 3:
    value = num9;
    y = 70;
    value2 = num11;
    value3 = num12;
    break;
    case 4:
    value = num13;
    y = 80;
    value2 = num15;
    value3 = num16;
    break;
    case 5:
    value = num17;
    y = 90;
    value2 = num19;
    value3 = num20;
    break;
    for ( int j = 1; j <= value2; j++ )
    g.fillRect ( value *= 10, y, value2 *= 10, value3 *= 10 );
    }

    Hi,
    Maybe the code below can help you out.
    import javax.swing.*;
    import java.awt.*;
    //import java.text.*;
        <APPLET CODE="fillRect" WIDTH=600 HEIGHT=400></APPLET>
    public class fillRect extends JApplet
      private final int NUM_RECTS = 4;
      private int rectWidth, rectHeight, rectX, rectY;
      private int getInput( String prompt, int lowValid, int highValid )
        int outVal = Integer.MIN_VALUE;
        boolean valid = false;
        while( !valid )
          String inputString = JOptionPane.showInputDialog( prompt );
          try
            outVal = Integer.parseInt( inputString );
            if( outVal >= lowValid && outVal <= highValid )
              valid = true;
            else
              throw new NumberFormatException();
          catch( NumberFormatException nfee )
            JOptionPane.showMessageDialog( null, "Invalid: Must be between " +
                                           lowValid + " and " + highValid + ".",
                                           "Error", JOptionPane.ERROR_MESSAGE );
        return( outVal );
      public void init()
        // Get inputs from user.
        rectX = getInput( "Please enter the upper left X-coordinate value:",
                          1, Integer.MAX_VALUE );
        rectY = getInput( "Please enter the upper left y-coordinate value:",
                          1, Integer.MAX_VALUE );
        rectWidth = getInput( "Please enter the width (non-negative):", 1, 100 );
        rectHeight = getInput( "Please enter the height (non-negative):", 1, 100 );
      public void paint( Graphics g)
        if( rectX > 1 )
          Dimension dim = getSize();
          g.setColor( Color.cyan );
          g.fillRect( rectX, rectY, rectWidth, rectHeight );
          for( int j = 1; j < NUM_RECTS; ++j )
            int offsetX = (int)(Math.random() * (dim.width - rectWidth));
            int offsetY = (int)(Math.random() * (dim.height - rectHeight));
            g.fillRect( rectX+offsetX, rectY+offsetY, rectWidth, rectHeight );
    }Regards,
    Manfred.

  • Referencing DLL in JApplet

    i have native elements i wish to include in one of my JApplets
    I've tested the DLL using a command line style program, and it connects fine. Hence I am confident the DLL itself was built properly.
    However, when i use an init() method instead of a main() (start with appletviewer instead of java.exe), it gives an access denied message. Are applets 'not allowed' to open DLLs. If not, there must be some sort of security setting that I have overseen
    i use this code in the JApplet subclass, outside other methods
    static {
    try {
    System.loadLibrary("MyWindow");
    } catch (Exception e) {
    JOptionPane.showMessageDialog(frame, e.getMessage());
    }any help loading native elements in JApplet would be appreciated
    mike

    Mike,
    Chris is correct. You will have to sign the applet. What's more...you are correct you will have to copy the dll to the users filesystem. I have been working on this for a couple weeks and here are my findings.
    Project:
    Create an applet that can access the clients com ports.
    Requiremnents:
    Comm port access requires the win32com.dll, the comm.jar api code and the javax.comm.properties files.
    Findings:
    The ONLY way for native library access(i.e to the dll) is for that DLL to reside on the clients local drive. I tried everything and did a ton of research...I even despeartely tried to change the java.lang.Classloader (which was of course forbidden). There's a private vector in Classloader that stores the native libraries and the only way to get added to that vector is to be one the local hard drive.
    What this means:
    You either need the client to already have the dll installed or you need your applet to write it to their filesystem. Also if you are using the loadLibrary method instead of the load method you must make sure the dll is written to a location that is in the user's path.
    The ONLY way to write a file to the clients machine is to have file write permission. To do this your applet will have to be signed. It may not be elegant but that's all you've got.(Or you can ask the user to edit their java.policy file...ha!). Signing really isn't that big of a deal...scary would be allowing you to access the DLL without signing your code....yikes!
    Conclusion:
    Once you have written the dll to the users local system (in my case the win32com.dll) my signed applet along with the signed version of the comm.jar are able to open and communicate with the com ports. If you would like some code snippets or more detail on my implementation I'd be happy to post them
    P.S. Anyone implementatingthe java.comm example specifically will also have to copy the javax.comm.properties file to the users drive. Otherwise the driver intializer will return name cannot be null ...you could probably fix this if you modified the comm package slightly but it's a bit of a blackbox since sun isn't giving away the source code

  • JOptionPane and Applet problem

    Hi folks,
    I have an applet, I want to display a pop up dialog whenever the user
    does something. SO i used JOptionPane:
    int userIn=JOptionPane.showInternalConfirmDialog(this,"Do you wish to generate xml for each ics/ids files pair in this data set?", "information",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
    //repaint();
    The dialog just doesn't show up, I tried repaint(), tried JApplet, nothing works, what am I missing? I'm pretty sure the above code gets called.
    thanks

    A. Are you sure this code is executing?
    B. Are you sure you aren't getting an error, possibly something like
    java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
    at javax.swing.JOptionPane.createInternalFrame(JOptionPane.java:1161)
    at javax.swing.JOptionPane.showInternalOptionDialog(JOptionPane.java:1025)
    at javax.swing.JOptionPane.showInternalConfirmDialog(JOptionPane.java:967)
    at javax.swing.JOptionPane.showInternalConfirmDialog(JOptionPane.java:931)

  • JOptionPane.showMessageDialog vs JOptionPane.showInternalMessageDialog

    This is my first post to the message boards, so please don't be too hard on me if this is really obvious...
    I'm trying to show a pop-up box with a message to indicate an error to the user; the JOptionPane.showMessageDialog works just fine, however when I use JOptionPane.showInternalMessageDialog, I get a NullPointerException being thrown by the L&F component(s) as follows (I'm currently running this as an applet via appletviewer):
    Exception occurred during event dispatching:
    java.lang.NullPointerException
    at javax.swing.plaf.metal.MetalLookAndFeel.getPrimaryControlDarkShadow(MetalLookAndFeel.java:1083)
    at javax.swing.plaf.metal.MetalBorders$OptionDialogBorder.paintBorder(MetalBorders.java:188)
    at javax.swing.JComponent.paintBorder(JComponent.java:574)
    at javax.swing.JComponent.paint(JComponent.java:740)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:23)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:54)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:91)
    at java.awt.Container.paint(Container.java:960)
    at java.awt.Container.update(Container.java:981)
    at sun.awt.RepaintArea.update(RepaintArea.java:337)
    at sun.awt.motif.MComponentPeer.handleEvent(MComponentPeer.java:404)
    at java.awt.Component.dispatchEventImpl(Component.java:2722)
    at java.awt.Container.dispatchEventImpl(Container.java:1214)
    at java.awt.Component.dispatchEvent(Component.java:2556)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:333)
    at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
    I guess that I've really got two questions about this whole thing... 1) What could be causing the NullPointerException and 2) What is the real difference between JOptionPane.showMessageDialog and JOptionPane.showInternalMessageDialog?

    Here's the call that I'm using to the function -- sorry for not posting that originally...
    JOptionPane.showInternalMessageDialog( this, getString( "Messages.NoPOsSelected" ), "Error", JOptionPane.ERROR_MESSAGE );Where "this" should be the applet itself, since this is being called from a function within the JApplet.

  • JApplet and the Images --PLEASE reply fast

    the problem is i am trying to put a .gif image into JApplet. no matter what i do it just DOESNT WANNA WORK! can anyone please post an example of working one?

    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.lang.Object.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.border.LineBorder.*;
    import javax.swing.border.*;
    import javax.swing.*;
    import java.awt.*;
    import java.applet.*;
    import java.util.Random;
    public class MoveTheSquare  extends JApplet implements ActionListener
         public static int size = 100;
           public     static        int life = 80;
            public     static       int eneLife=50;
         private AudioClip ohboy2= getAudioClip(getDocumentBase(), "ohboy2.wav");
    //      public Image bricks = getImage(getDocumentBase(),"bricks.gif");
        public static void main(String[] args)
            ApplicationFrame frame = new ApplicationFrame();
            frame.setBounds(50, 50, 900, 900);
            frame.setVisible(true);
            new ApplicationFrame();
        private static class ApplicationFrame extends JFrame
            public ApplicationFrame()
            super("Move the Sticky Figure!");
               // setDefaultCloseOperation(EXIT_ON_CLOSE);
                setSize(500, 600);
                JPanel content = new JPanel();
                ((JPanel) getContentPane()).setOpaque(true);
               // new WindowListener(1);
                 ImageIcon bricks = new ImageIcon("bricks.gif");
                 JLabel backlabel = new JLabel(bricks);
                getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE));
                backlabel.setBounds(0,0,20000,2560);
                setLocation(500,600);
                  //WindowListener1 = new WindowAdapter() {
                  //public void windowClosing(WindowEvent e) {
                  //System.exit(0);
                  //setVisible(true);
                initUi();
            private void initUi()
                Container cp = getContentPane();
                Image img = getImage(getDocumentBase(), "bricks.gif" );
                cp.add(new MyPanel(img));
                cp.setLayout( new BorderLayout(0, 10) );
              //   addWindowListener1();
                cp.add( new JLabel(" Move the Sticky with the arrow keys:"), BorderLayout.NORTH );
                // Create the playing board and the squar
                Square sq = new Square( new Point(100, 100), 10 );
                Board board = new Board(sq);
                cp.add( board, BorderLayout.CENTER );
                // Register Key Bindings to move the square around. Read about the
                InputMap im = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
                ActionMap am = getRootPane().getActionMap();
                // The LEFT arrow will move the suare to pixels two the left
                MoveSquareAction moveLeft = new MoveSquareAction(board, -3, 0);
                KeyStroke keyStrokeLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0);
                im.put( keyStrokeLeft, "left" );
                am.put( "left", moveLeft );
                // The RIGHT arrow will move the suare to pixels two the right
                MoveSquareAction moveRight = new MoveSquareAction(board, 3, 0);
                KeyStroke keyStrokeRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0);
                im.put( keyStrokeRight, "right" );
                am.put( "right", moveRight );
                // The UP arrow will move the suare two pixels up
                MoveSquareAction moveUp = new MoveSquareAction(board, 0, -3);
                KeyStroke keyStrokeUp = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
                im.put( keyStrokeUp, "up" );
                am.put( "up", moveUp );
                // The DOWN arrow will move the suare two pixels down
                MoveSquareAction moveDown = new MoveSquareAction(board, 0, 3);
                KeyStroke keyStrokeDown = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
                im.put( keyStrokeDown, "down" );
                am.put( "down", moveDown );
                pack();
        // Class that represents the playing board
        private static class Board extends JPanel
              private Square square;
            public Board(Square sq)
                square = sq;
                setOpaque(true);
                setBorder( new LineBorder(Color.GREEN));
            int x=1;
            public void  paintComponent(Graphics g)
                super.paintComponent(g);
                g.drawImage( img, currentX, currentY, this );
                   if (x==1)
                Point location = square.getLocation();
                String coordX = String.valueOf(location.x);
                String coordY = String.valueOf(location.y);
                String slife = String.valueOf(life);
                    //g.drawImage(bricks, 0, 0, 500, 16, this);
                  g.setColor(Color.red);
                   g.fillRect(240,240,250,250);
                   g.setColor(Color.GREEN);
                   g.fillRect(0,00,40,40);
                   g.setColor(Color.black);
                g.drawLine(location.x-5,location.y+5,location.x,location.y);
                   g.drawLine(location.x+5,location.y+5,location.x,location.y);
                   g.drawLine(location.x,location.y,location.x,location.y-7);
                   g.drawLine(location.x-4,location.y-4,location.x,location.y-7);
                   g.drawLine(location.x+4,location.y-4,location.x,location.y-7);
                   g.fillOval(location.x-3,location.y-15,8,8);
                   g.drawString(coordX,20,20);
                   g.drawString(coordY,20,30);
                   g.drawString("YOUR LIFE:", 00,70);
                   g.drawString(slife,70,70);
                   Random generator = new Random();
                  int takeaway = generator.nextInt(25);
                     int fight = generator.nextInt(50);
                   if (fight==4)
                  x=0;
                 life= life-takeaway;
                  JOptionPane.showMessageDialog(null, "YOU ARE BEING ATTACKED!!!!! YOU LOST HEALTH:" +takeaway);
                    slife = String.valueOf(life);
                 g.drawString(slife,70,70);
                 if (life<=0)
                 JOptionPane.showMessageDialog(null, "you lose. bye.");
                 System.exit(0);
                 if (((location.x>=240) && (location.y>=240)) &&((location.x<=490) && (location.y<=490)))
                 JOptionPane.showMessageDialog(null, "you Win! bye.");
                 System.exit(0);
           Random generator = new Random();
           int fight = generator.nextInt(50);
           if (fight==1)
           x=1;
            public Square getSquare()
                return square;
        // The Action class that implements moving the square:
        private static class MoveSquareAction extends AbstractAction
            // The board this action acts on:
            Board board;
            // The number of pixels to move in the X- and Y-directions:
            int pixelsToMoveX;
            int pixelsToMoveY;
            public MoveSquareAction(Board board, int pixelsToMoveX, int pixelsToMoveY)
                this.board = board;
                this.pixelsToMoveX = pixelsToMoveX;
                this.pixelsToMoveY = pixelsToMoveY;
            public void actionPerformed(ActionEvent e)
                // Move the square and repaint the board:
                board.getSquare().moveX(pixelsToMoveX);
                board.getSquare().moveY(pixelsToMoveY);
                board.repaint();
        // Class that represents the black square we move around
        private static class Square
            private Point     location;
            private int          size;
            public Square(Point loc, int size)
                location = loc;
                this.size = size;
            public Point getLocation()
                return location;
            public int getSize()
                return size;
            public void moveX(int pixels)
                location.x += pixels;
            public void moveY(int pixels)
                location.y += pixels;
        public void actionPerformed(ActionEvent e)
                 ohboy2.loop();//sound
    }

  • JApplet calls a Class. This Class needs Input

    I am doing something in a JApplet. After the user click in a jButton called Execute, this JApplet use a class (Processing) to process some inputs which comes meanwhile this class (Processing) is running. I need some input from the user but not in the way of JOptionPane. I would like to show some more elegant dialog with checkboxes and buttons. How can I do this? Thx for help me!

    I am doing something in a JApplet. After the user click in a jButton called Execute, this JApplet use a class (Processing) to process some inputs which comes meanwhile this class (Processing) is running. I need some input from the user but not in the way of JOptionPane. I would like to show some more elegant dialog with checkboxes and buttons. How can I do this? Thx for help me!

  • Freezed modal jdialog in japplet

    I have made an applet program whose method javascript calls. And the method of the applet shows modal JDialog. But, after showing modal JDialog, the applet is locked.
    In Windows XP + JRE 6.2 + Firefox 2.0, it is locked just after showing modal JDialog.
    But in Windowx XP + JRE 5,4,3 + Firefox 2.0/IE, it is OK(working well) And, in Other OSes and Other browser, it is OK
    You can test this and watch java source in the below link.
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.html
    http://whoispso.cafe24.com/freezed_dialog_in_ff/FreezedJDialogInFFInJRE6InWindows.java
    import java.awt.Frame;
    import javax.swing.JApplet;
    import javax.swing.JDialog;
    import javax.swing.JOptionPane;
    public class FreezedJDialogInFFInJRE6InWindows extends JApplet {
         private Frame rootFrame;
         public void init() {
              rootFrame = JOptionPane.getFrameForComponent(this);
              showJDialog("it is called from init()");          
         public String showJDialogFromJS() {
              String msg = "it is called from showJDialogFromJS()";
              showJDialog(msg);
              return msg;          
         private void showJDialog(String msg) {
              JDialog dialog = new JDialog(rootFrame, msg, true);
              dialog.setSize(300, 300);
              dialog.setResizable(false);
              dialog.setVisible(true);
    {code}
    {code:javascript}
    <HTML>
    <HEAD>
         <SCRIPT language = "javascript">
              function install() {
                   var applet_tag = '<APPLET ID = "dialog_test"' +
                                       'CODE = "FreezedJDialogInIEInJRE5InWindows.class"' +
                                       'WIDTH = "0"' +
                                       'HEIGHT = "0">';
                   document.getElementById("applet_space").innerHTML = applet_tag;
              function showJDialog() {
                   if(!is_installed()) {
                        alert("not installed!");
                        return;
                   var returnValue;
                   try {
                        returnValue = document.dialog_test.showJDialogFromJS();
                   } catch (err) {
                        alert(err);
                   alert("return value is " + returnValue);
              function is_installed() {
                   if(document.dialog_test == null) {
                        return false;
                   } else {
                        return true;
         </SCRIPT>
    </HEAD>
    <BODY>
    <DIV id = "applet_space"></DIV>
    <SCRIPT>
         install();
    </SCRIPT>
    <INPUT TYPE="button" NAME="button" VALUE="showJDialog()" onClick=javascript:showJDialog()>
    </BODY>
    </HTML>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try placing it on the awt thread, for example:
    private void showJDialog(String msg) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                          JDialog dialog = new JDialog(rootFrame, msg, true);
                          dialog.setSize(300, 300);
                          dialog.setResizable(false);
                          dialog.setVisible(true);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Halt code execution while awaiting a return value - like JOptionPane..

    I've been struggling with a minor annoying problem...
    I want to achive kindda the same thing as what happens when you call: String s = JOptionPane.showInputDialog(...);
    The code execution locks until a value is returned, and this is exactly what I want to be able to do with my own custom dialog/frame/whatever.
    Obviously, wait() and notify() on the calling thread won't work, so how can I achieve this optionpane gui-code-locking behaviour with my own custom gui components?
    Thx in advance !

    From JInternalFrame source:
         * Creates a new <code>EventDispatchThread</code> to dispatch events
         * from. This method returns when <code>stopModal</code> is invoked.
        synchronized void startModal() {
         /* Since all input will be blocked until this dialog is dismissed,
          * make sure its parent containers are visible first (this component
          * is tested below).  This is necessary for JApplets, because
          * because an applet normally isn't made visible until after its
          * start() method returns -- if this method is called from start(),
          * the applet will appear to hang while an invisible modal frame
          * waits for input.
         if (isVisible() && !isShowing()) {
             Container parent = this.getParent();
             while (parent != null) {
              if (parent.isVisible() == false) {
                  parent.setVisible(true);
              parent = parent.getParent();
            try {
                if (SwingUtilities.isEventDispatchThread()) {
                    EventQueue theQueue = getToolkit().getSystemEventQueue();
                    while (isVisible()) {
                        // This is essentially the body of EventDispatchThread
                        AWTEvent event = theQueue.getNextEvent();
                        Object src = event.getSource();
                        // can't call theQueue.dispatchEvent, so I pasted its body here
                        if (event instanceof ActiveEvent) {
                            ((ActiveEvent) event).dispatch();
                        } else if (src instanceof Component) {
                            ((Component) src).dispatchEvent(event);
                        } else if (src instanceof MenuComponent) {
                            ((MenuComponent) src).dispatchEvent(event);
                        } else {
                            System.err.println("unable to dispatch event: " + event);
                } else
                    while (isVisible())
                        wait();
            } catch(InterruptedException e){}
         * Stops the event dispatching loop created by a previous call to
         * <code>startModal</code>.
        synchronized void stopModal() {
            notifyAll();
        }It basically works like this:
    If this thread is not the EventDispatcher, then just use wait() and notify().
    If it is the EventDispatcher...the process the events from here while we wait for the dialog to close. Seems kind of dirty, but it works.

  • Regarding  problem  of database connectivity of JApplet

    Below written code gives the error "JAVA.Lang.RuntimePermissionaccessClasslnPackage.sun.jdbc.odbc".
    import javax.swing.*;
    import java.sql.*;
    import java.awt.event.*;
    import java.awt.*;
    public class appletDatabase extends JApplet implements ActionListener {
    JLabel l1;
    JLabel l2;
    JLabel l3;
    JTextField tf1;
    JPasswordField tf2;
    JButton btn;
    Connection cn;
    Statement st;
    String hostname;
    public void init() {
    //hostname = "localhost";
    l1 = new JLabel("User Name: ");
    l2 = new JLabel(" Password: ");
    l3 = new JLabel(" ");
    tf1 = new JTextField(20);
    tf2 = new JPasswordField(20);
    btn = new JButton("Sign in");
    Container c = getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.LEFT));
    c.add(l1);
    c.add(tf1);
    c.add(l2);
    c.add(tf2);
    c.add(btn);
    c.add(l3);
    btn.addActionListener(this);
    setSize(300,300);
    setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource()==btn)
         JOptionPane.showMessageDialog(null,"btn click");
         check();
         JOptionPane.showMessageDialog(null,"success");
    public void check() {
    String query="SELECT * from TBJAVA";
    try {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         cn = DriverManager.getConnection("jdbc:odbc:Temp","trg123","training");
         st = cn.createStatement();
         ResultSet rs = st.executeQuery(query);}
    /*if (!(rs==null))
    if (rs.next())
    b = true;
    rs.close();
    st.close();
    cn.close();
    /* catch (SQLException e1) {
              e1.printStackTrace();
              JOptionPane.showMessageDialog(null,"error in sql exception");
    catch (ClassNotFoundException e1) {
              e1.printStackTrace();
              JOptionPane.showMessageDialog(null,"error in class not founf");
         catch (Exception e1) {
              e1.printStackTrace();
              JOptionPane.showMessageDialog(null,"error in exception"+e1.getMessage());
    corresponding HTML code is given below:
    <html>
    <head>
    </head>
    <body><applet code="appletDatabase" width =400 height =400></applet>
    </body>
    </html>
    Please help
    regards
    kamal preet

    Please use code tags when posting code
    Applet sandbox do not allow you to access local system respurces unless the applet is signed.
    jdbc:odbc bridge always connect to the ODBC interface in the local system.

Maybe you are looking for