Results 1 to 16 of 16
  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Problem with my applet.

    When I run the applet on my computer it works perfectly (I am using Linux (ubuntu)), and when I've tried to run it on my sister's laptop it doesn't work. Well it works, it shows the GUI, but the buttons don't work, and t doesn't get the news from the MySQL database. (My sister is running Windows 7)

    This is my applet:
    Java Code:
    import com.mysql.jdbc.Connection;
    import com.mysql.jdbc.PreparedStatement;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.text.*;
    
    public class mainApplet extends JApplet {
    
        public void sM(String s, Color c) {
            SimpleAttributeSet aset = new SimpleAttributeSet();
            StyleConstants.setForeground(aset, c);
    
            textArea.setEditable(true);
            int len = textArea.getText().length();
            textArea.setCaretPosition(len);
            textArea.setCharacterAttributes(aset, false);
            textArea.replaceSelection(s + "\n");
            textArea.setEditable(false);
        }
        public SwingWorker worker;
    
        @Override
        public void init() {
            getNews();
    
            initComponents();
            worker.execute();
    
    
        }
        //Panels
        private JTabbedPane tabpane;
        private JPanel welcomePanel;
        private JScrollPane scrollPane;
        private JPanel optionsPanel;
        private JPanel loginPanel;
        //Content
        private JLabel welcomeLabel;
        private JLabel newsLabel;
        private JLabel newsLabel1;
        private JLabel mousePositionLabel;
        private JLabel loginUsernameLabel;
        private JLabel loginPasswordLabel;
        public JTextPane textArea;
        private JButton updateNews;
        private JTextField loginUsername;
    
        public void initComponents() {
            textArea = new JTextPane();
            sM("Loading StreetWars", Color.BLACK);
            tabpane = new JTabbedPane();
            add(tabpane);
            new Font("Serif", Font.PLAIN, 24);
            welcomePanel = new JPanel();
            welcomePanel.setLayout(null);
            welcomeLabel = new JLabel("Welcome to Street Wars, please choose one of the tabs to continue.");
    
            welcomePanel.add(welcomeLabel);
    
            mousePositionLabel = new JLabel();
            welcomeLabel.setFont(new Font("DejaVu Serif", Font.PLAIN, 20));
            welcomePanel.add(mousePositionLabel);
            newsLabel = new JLabel("Latest News");
            newsLabel.setFont(new Font("DejaVu Serif", Font.PLAIN, 17));
            newsLabel1 = new JLabel("L");
            welcomePanel.add(newsLabel1);
            welcomePanel.add(newsLabel);
    
            //NEWS
    
            welcomePanel.addMouseMotionListener(new MouseAdapter() {
    
                private String MOUSE_POS;
    
                @Override
                public void mouseMoved(MouseEvent e) {
                    String labelTxt = MOUSE_POS + String.format("[%d, %d]", e.getPoint().x, e.getPoint().y);
                    mousePositionLabel.setText(labelTxt);
                }
            });
    
    
            //Options Panel
            optionsPanel = new JPanel();
            optionsPanel.setLayout(null);
            textArea.setBackground(Color.LIGHT_GRAY);
            textArea.setEditable(false);
            scrollPane = new JScrollPane();
            scrollPane.setViewportView(textArea);
            scrollPane.setSize(550, 550);
            scrollPane.setSize(300, 200);
            optionsPanel.add(scrollPane);
            updateNews = new JButton("Update News");
            updateNews.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
                    sM("Test", Color.red);
                }
            });
            optionsPanel.add(updateNews);
    
            //LOGIN PANEL
            loginPanel = new JPanel();
            loginUsernameLabel = new JLabel("Username: ");
            loginPasswordLabel = new JLabel("Password : ");
    
            loginPanel.add(loginUsernameLabel);
            loginPanel.add(loginPasswordLabel);
    
    
            //TABS
            tabpane.add("Welcome", welcomePanel);
            tabpane.add("Login", loginPanel);
            tabpane.add("Options", optionsPanel);
    
            Positions();
            
        }
    
        public void Positions() {
            //Welcome Panel
            Insets insets = welcomePanel.getInsets();
            Dimension size = welcomeLabel.getPreferredSize();
            welcomeLabel.setBounds(5 + insets.left, 5 + insets.top,
                    size.width, size.height);
    
            size = newsLabel.getPreferredSize();
            newsLabel.setBounds(5 + insets.left, 125 + insets.top,
                    size.width, size.height);
            size = newsLabel1.getPreferredSize();
            newsLabel1.setBounds(5 + insets.left, -90 + insets.top,
                    size.width + 690, size.height + 500);
    
            size = mousePositionLabel.getPreferredSize();
            mousePositionLabel.setBounds(5 + insets.left, 5 + insets.top,
                    size.width + 500, size.height + 500);
    
            //Options Panel
            insets = scrollPane.getInsets();
            size = scrollPane.getPreferredSize();
            scrollPane.setBounds(5 + insets.left, 5 + insets.top,
                    size.width + 550, size.height + 160);
            size = updateNews.getPreferredSize();
            updateNews.setBounds(5 + insets.left, 215 + insets.top,
                    size.width, size.height);
    
            //Login Panel
            insets = loginPanel.getInsets();
            size = loginPanel.getPreferredSize();
            size = loginUsernameLabel.getPreferredSize();
            loginUsernameLabel.setBounds(5 + insets.left, 215 + insets.top,
                    size.width, size.height);
        }
    
        // GET NEWS
        public void getNews() {
            worker = new SwingWorker() {
    
                @Override
                protected Object doInBackground() throws Exception {
                    sM("Connecting to DB", Color.BLACK);
                    newsLabel1.setText("Loading...");
                    try {
                        Class.forName("com.mysql.jdbc.Driver");
                    } catch (ClassNotFoundException ex) {
                        sM("ERROR ON LINE 158 : " + ex.toString() + "", Color.RED);
                    }
                    Connection con = null;
                    try {
                        con = (Connection) DriverManager.getConnection("jdbc:mysql:/****sw", "d****k****sw", "k*****");
                    } catch (SQLException ex) {
                        sM("ERROR ON LINE 164 : " + ex.toString() + "", Color.RED);
                    }
                    PreparedStatement statement = null;
                    try {
                        statement = (PreparedStatement) con.prepareStatement("select * from news ORDER BY `id` DESC LIMIT 0 , 1");
                        sM("Getting the news", Color.BLACK);
                    } catch (SQLException ex) {
                        sM("ERROR ON LINE 171 : " + ex.toString() + "", Color.RED);
                    }
                    ResultSet result = null;
                    try {
                        result = statement.executeQuery();
                    } catch (SQLException ex) {
                        sM("ERROR ON LINE 177 : " + ex.toString() + "", Color.RED);
                    }
    
                    try {
                        while (result.next()) {
                            newsLabel1.setText(result.getString(2));
                        }
                    } catch (SQLException ex) {
                        sM("ERROR ON LINE 184 : " + ex.toString() + "", Color.RED);
                    }
                    sM("Done!", Color.GREEN);
                    try {
                        sM("Closing the connection", Color.RED);
                        con.close();
                    } catch (SQLException ex) {
                        sM("ERROR ON LINE 191 : " + ex.toString() + "", Color.RED);
                    }
                    sM("Done!", Color.GREEN);
    
                    sM("-------------------------------------------------", Color.GREEN);
                    return null;
                }
            };
        }
        private SwingWorker regWorker;
    
        public void Registration() {
            regWorker = new SwingWorker() {
    
                @Override
                protected Object doInBackground() throws Exception {
    
                    return null;
                }
            };
        }
    }
    And if you would like to have a look at the applet click here -> Test page for launching the applet via JNLP
    Last edited by PhQ; 04-03-2010 at 05:12 PM.

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    By the way...
    When you run the applet the Latest News should be 'News', when when you go to the Options tab the it should say:
    Loading StreetWars
    Connecting to DB
    Getting the news
    Done!
    Closing the connection
    Done!
    -------------------------------------------------

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    If so, looking at your output, are you sure that in DB you have data? Basically do you refer the same DB?

  4. #4
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Eranga View Post
    If so, looking at your output, are you sure that in DB you have data? Basically do you refer the same DB?
    Yes I have some data in my DB (if is that what you mean).
    And when you click Update News in Options it should say TEST in the output thing.


    this is what it should look like.

    EDIT:: DOESN'T WORK ON MY MUM's COMPUTER. (She is runining Windows XP)
    Last edited by PhQ; 04-03-2010 at 06:15 PM.

  5. #5
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Provide your exception text here plz.

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    But I suppose your db connection problem :)

    Java Code:
    Connection con = null;
                    try {
                        [B]con = (Connection) DriverManager.getConnection("jdbc:mysql:/****sw", "d****k****sw", "k*****");[/B]                } catch (SQLException ex) {
                        sM("ERROR ON LINE 164 : " + ex.toString() + "", Color.RED);
                    }
    Unsigned applets cannot connect to non native host ;)

    Report if that helps :)

  7. #7
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    There is no exception.
    It just doesn't do anything.
    I think my applet is signed, I am using NetBeans and you can click 'Self Signed'.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    Unsigned applets cannot connect to non native host ;)
    Yea, as far as I know you cannot do that.

    And I think there is no inbuilt way to sign your applet in Java. To confirm that once you build the application extract the JAR file and check on META-INF file for any verification details.

  9. #9
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    So what can I do?
    And how come that it works perfectly on my computer?
    Last edited by PhQ; 04-04-2010 at 03:50 PM.

  10. #10
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Ok,
    I have found the problem, there is something wrong with my sM method...
    I have deleted all of the sM declarations or what ever (sorry I've forgot what they are called), and it works.
    Can anyone tell me what's wrong?

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Looking at your method, I cannot see any stuff which can cause for your issue. Did you debug the code? Seems to me, the initialization is okay, Except one thing.

    Java Code:
        public void sM(String s, Color c) {
            SimpleAttributeSet aset = new SimpleAttributeSet();
            StyleConstants.setForeground(aset, c);
    
            textArea.setEditable(true);
            int len = textArea.getText().length();
            textArea.setCaretPosition(len);
            textArea.setCharacterAttributes(aset, false);
            textArea.replaceSelection(s + "\n");
            textArea.setEditable(false);
        }
    textArea enable and disable in your code, which is not necessary to do. Even the control is disable programatically you can use it, setEditable() only do the user interaction restricted.

  12. #12
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    As I may think

    your code is
    Java Code:
    public void init() {
            getNews();
    
            initComponents();
            worker.execute();
    
    
        }
    I think you should modify it as

    Java Code:
    public void init() {
            
    initComponents();
    getNews();    
            worker.execute();
    
    
        }
    because Java supports linear code running :rolleyes:
    Last edited by Webuser; 04-07-2010 at 03:37 AM.

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmm, that's a very good point lol. I've never think about that. With dynamic UI changes this can be effect. Better to give a try and see by our OP.

  14. #14
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Yay, that worked.
    Thank you very much. :)

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  16. #16
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Exclamation

    Quote Originally Posted by PhQ View Post
    Yay, that worked.
    Thank you very much. :)
    Good Java Coding

Similar Threads

  1. applet and JPS problem.... please help me
    By rockster14 in forum Java Applets
    Replies: 0
    Last Post: 08-07-2009, 11:44 PM
  2. applet problem
    By shwein in forum New To Java
    Replies: 2
    Last Post: 10-28-2008, 12:17 AM
  3. Serious applet problem
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-25-2008, 06:01 PM
  4. applet problem plz HELP
    By shibajisanyal in forum Java Applets
    Replies: 1
    Last Post: 01-09-2008, 02:47 AM
  5. Applet problem
    By Ed in forum Java Applets
    Replies: 2
    Last Post: 07-02-2007, 04:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •