#1
  1. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0

    What is wrong with this?


    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package klientesis;
    
    /**
     *
     * @author Tawi
     */
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class KlienTesis extends JFrame{
    
        /**
         * @param args the command line arguments
         */
        private JTextField jtf = new JTextField();
        private JTextArea jta = new JTextArea();
        private DataInputStream fromServer;
        private DataOutputStream toServer;
        
        public static void main(String[] args) {
            new KlienTesis(); // TODO code application logic here
        }
        public KlienTesis() {
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            p.add(new JLabel("Masukkan Radius: "), BorderLayout.WEST);
            p.add(jtf, BorderLayout.CENTER);
            jtf.setHorizontalAlignment(JTextField.RIGHT);
            setLayout(new BorderLayout());
            add(new JScrollPane(jta), BorderLayout.CENTER);
            jtf.addActionListener(new ButtonListener());
            setTitle("Klien");
            setSize(1024,768);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            try {
                Socket hubungkan = new Socket("localhost", 8000);
                fromServer = new DataInputStream(hubungkan.getInputStream());
                toServer = new DataOutputStream(hubungkan.getOutputStream());
            }
            catch (IOException ex) {
                jta.append(ex.toString() + '\n');
                ex.printStackTrace();
            }
        }
    
        private class ButtonListener implements ActionListener {
           public void actionPerformed(ActionEvent ex) {
               try {
                   double radius = Double.parseDouble(jtf.getText().trim());
                   toServer.writeDouble(radius);
                   toServer.flush();
                   double area = fromServer.readDouble();
                   jta.append("Radius yaitu: " + radius + '\n');
                   jta.append("Luas yang Didapatkan dari Server yaitu: " + area + '\n');
               }
               catch (IOException e) {
                   System.err.println(e);
                   e.printStackTrace();
               }
           }
        }
    }
    It shows nothing but a blank white screen. What should I do to fix this?
    Last edited by Tawijakarta; July 27th, 2013 at 11:53 AM.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    What happens if the definition of jta is changed like this:
    Code:
        private JTextArea jta = new JTextArea("This is the JTextArea\n\n\n\nSeveral lines\n");    //<<<<<<<<<<<
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    It shows just like you want to show but no JLabel, how to change it?
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    If you want to add other components to the JFrame, you need to use the add() method.
  8. #5
  9. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    There is a command to add a JLabel. Why doesn't it work?
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    There is a command to add a JLabel. Why doesn't it work?
    Please post the code showing where a JLabel is being added to the GUI.
    Be sure to add some comments to the statement that you think should be adding the JLabel to the GUI being shown in the JFrame so that I can see exactly which statements you are talking about.
  12. #7
  13. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Please post the code showing where a JLabel is being added to the GUI.
    Be sure to add some comments to the statement that you think should be adding the JLabel to the GUI being shown in the JFrame so that I can see exactly which statements you are talking about.
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package klientesis;
    
    /**
     *
     * @author Tawi
     */
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class KlienTesis extends JFrame{
    
        /**
         * @param args the command line arguments
         */
        private JTextField jtf = new JTextField();
        private JTextArea jta = new JTextArea();
        private DataInputStream fromServer;
        private DataOutputStream toServer;
        
        public static void main(String[] args) {
            new KlienTesis(); // TODO code application logic here
        }
        public KlienTesis() {
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            p.add(new JLabel("Masukkan Radius: "), BorderLayout.WEST); // <<<< I put the JLabel in here
            p.add(jtf, BorderLayout.CENTER);
            jtf.setHorizontalAlignment(JTextField.RIGHT);
            setLayout(new BorderLayout());
            add(new JScrollPane(jta), BorderLayout.CENTER);
            jtf.addActionListener(new ButtonListener());
            setTitle("Klien");
            setSize(1024,768);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            try {
                Socket hubungkan = new Socket("localhost", 8000);
                fromServer = new DataInputStream(hubungkan.getInputStream());
                toServer = new DataOutputStream(hubungkan.getOutputStream());
            }
            catch (IOException ex) {
                jta.append(ex.toString() + '\n');
                ex.printStackTrace();
            }
        }
    
        private class ButtonListener implements ActionListener {
           public void actionPerformed(ActionEvent ex) {
               try {
                   double radius = Double.parseDouble(jtf.getText().trim());
                   toServer.writeDouble(radius);
                   toServer.flush();
                   double area = fromServer.readDouble();
                   jta.append("Radius yaitu: " + radius + '\n');
                   jta.append("Luas yang Didapatkan dari Server yaitu: " + area + '\n');
               }
               catch (IOException e) {
                   System.err.println(e);
                   e.printStackTrace();
               }
           }
        }
    }
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Where is the p object added to the GUI? If it is not added, it will NOT be shown.

    This is the only call to the add() method I see:
    Code:
        add(new JScrollPane(jta), BorderLayout.CENTER);
  16. #9
  17. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Nothing is happening any ways. So?
  18. #10
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    The posted code only adds one component to the GUI. If you want to see more, the code needs to add more components to the JFrame's container.
  20. #11
  21. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    It adds at least three components. What happens to the other components?
  22. #12
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    It adds at least three components
    Where are the other 2 components added to the JFrame' GUI? The code in post#7 only shows one.

    In post#6 I asked:
    Be sure to add some comments to the statement that you think should be adding the JLabel to the GUI being shown in the JFrame so that I can see exactly which statements you are talking about.
    Only one statement has the comment I asked for.

    Also see post#8. It shows the ONLY One component that is added to the JFrame's GUI.
  24. #13
  25. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Originally Posted by NormR
    Where are the other 2 components added to the JFrame' GUI? The code in post#7 only shows one.

    In post#6 I asked:
    Only one statement has the comment I asked for.

    Also see post#8. It shows the ONLY One component that is added to the JFrame's GUI.
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package klientesis;
    
    /**
     *
     * @author Tawi
     */
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class KlienTesis extends JFrame{
    
        /**
         * @param args the command line arguments
         */
        private JTextField jtf = new JTextField();
        private JTextArea jta = new JTextArea();
        private DataInputStream fromServer;
        private DataOutputStream toServer;
        
        public static void main(String[] args) {
            new KlienTesis(); // TODO code application logic here
        }
        public KlienTesis() {
            JPanel p = new JPanel();
            p.setLayout(new BorderLayout());
            p.add(new JLabel("Masukkan Radius: "), BorderLayout.WEST); // <<<< I put the JLabel in here
            p.add(jtf, BorderLayout.CENTER); // <<<< This is the other component.
            jtf.setHorizontalAlignment(JTextField.RIGHT);
            setLayout(new BorderLayout());
            add(new JScrollPane(jta), BorderLayout.CENTER); // Another add, so?
            jtf.addActionListener(new ButtonListener());
            setTitle("Klien");
            setSize(1024,768);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            try {
                Socket hubungkan = new Socket("localhost", 8000);
                fromServer = new DataInputStream(hubungkan.getInputStream());
                toServer = new DataOutputStream(hubungkan.getOutputStream());
            }
            catch (IOException ex) {
                jta.append(ex.toString() + '\n');
                ex.printStackTrace();
            }
        }
    
        private class ButtonListener implements ActionListener {
           public void actionPerformed(ActionEvent ex) {
               try {
                   double radius = Double.parseDouble(jtf.getText().trim());
                   toServer.writeDouble(radius);
                   toServer.flush();
                   double area = fromServer.readDouble();
                   jta.append("Radius yaitu: " + radius + '\n');
                   jta.append("Luas yang Didapatkan dari Server yaitu: " + area + '\n');
               }
               catch (IOException e) {
                   System.err.println(e);
                   e.printStackTrace();
               }
           }
        }
    }
    Well?
    Last edited by Tawijakarta; July 27th, 2013 at 01:10 PM.
  26. #14
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    I only see ONE place that a component is added to the JFrame's GUI:
    Code:
      add(new JScrollPane(jta), BorderLayout.CENTER); // Another add, so?
    If a component is NOT added to the JFrame it will NOT be shown.
  28. #15
  29. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    257
    Rep Power
    0
    Ok, it is solved. It is ok if you want to close this thread.
    Last edited by Tawijakarta; July 27th, 2013 at 01:20 PM.

IMN logo majestic logo threadwatch logo seochat tools logo