g00se's Profile User Rating: *****

Reputation: 2874 Guru
Group:
Mentors
Active Posts:
12,215 (5.13 per day)
Joined:
20-September 08
Profile Views:
35,938
Last Active:
User is online A minute ago
Currently:
Viewing Topic: Networking over WAN in java

Previous Fields

Country:
GB
OS Preference:
Linux
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
Java

Latest Visitors

Icon   g00se has not set their status

Posts I've Made

  1. In Topic: Networking over WAN in java

    Posted 31 Mar 2015

    If you're trying to run a Java app on a hosting provider's web server then largely speaking you're going to find that hard. Or is it a machine in your own LAN? There certainly is a web server running
  2. In Topic: Read and save values different from the actual content in a JComboBox

    Posted 31 Mar 2015

    OK. Try the following:

    import java.awt.*;
    import java.awt.event.*;
    
    import java.io.*;
    
    import java.util.*;
    
    import javax.swing.*;
    
    
    public class D extends JPanel {
        JComboBox<MillisecondValue> combo1;
        JComboBox<MillisecondValue> combo2;
        JComboBox<MillisecondValue> combo3;
        JComboBox<MillisecondValue> combo4;
    
        public D() {
            JPanel buttonPanel = new JPanel();
            add(buttonPanel);
            buttonPanel.setLayout(new GridLayout(0, 2, 10, 10));
    
            combo1 = new JComboBox<MillisecondValue>();
            combo1.addItem(new MillisecondValue("1"));
            combo1.addItem(new MillisecondValue("2"));
            buttonPanel.add(combo1);
    
            combo2 = new JComboBox<MillisecondValue>();
            combo2.addItem(new MillisecondValue("1"));
            combo2.addItem(new MillisecondValue("2"));
            buttonPanel.add(combo2);
    
            combo3 = new JComboBox<MillisecondValue>();
            combo3.addItem(new MillisecondValue("1"));
            combo3.addItem(new MillisecondValue("2"));
            buttonPanel.add(combo3);
    
            combo4 = new JComboBox<MillisecondValue>();
            combo4.addItem(new MillisecondValue("1"));
            combo4.addItem(new MillisecondValue("2"));
            buttonPanel.add(combo4);
    
            ArrayList<String> list = new ArrayList<String>();
    
            try {
                InputStream ips = new FileInputStream("te.txt");
                InputStreamReader ipsr = new InputStreamReader(ips);
                BufferedReader br = new BufferedReader(ipsr);
    
                String line;
    
                while ((line = br.readLine()) != null) {
                    String[] s = line.split(" ");
                    list.add(s[0]);
                    list.add(s[1]);
                }
    
                br.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            combo1.setSelectedItem(new MillisecondValue(list.get(0)));
            combo2.setSelectedItem(new MillisecondValue(list.get(1)));
            combo3.setSelectedItem(new MillisecondValue(list.get(2)));
            combo4.setSelectedItem(new MillisecondValue(list.get(3)));
    
            JButton button = new JButton("SAVE");
            buttonPanel.add(button);
            button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            System.out.println("Saving...");
    
                            PrintWriter out = new PrintWriter(new File("D.txt"));
                            out.print(((MillisecondValue) combo1.getSelectedItem()).getValue());
                            out.print(" ");
                            out.print(((MillisecondValue) combo2.getSelectedItem()).getValue());
                            out.println();
                            out.print(((MillisecondValue) combo3.getSelectedItem()).getValue());
                            out.print(" ");
                            out.print(((MillisecondValue) combo4.getSelectedItem()).getValue());
                            out.close();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                });
        }
    
        public static void main(String[] args) {
            D app = new D();
            JFrame m = new JFrame("D");
            m.getContentPane().add(app);
            m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            m.pack();
            m.setVisible(true);
        }
    
        public class MillisecondValue {
            private int value;
    
            public MillisecondValue() {
            }
    
            public MillisecondValue(int value) {
                this.value = value;
            }
    
            public MillisecondValue(String value) {
                this.value = Integer.parseInt(value);
            }
    
            public int getValue() {
                return this.value;
            }
    
            public void setValue(int value) {
                this.value = value;
            }
    
            public void setValue(String value) {
                this.value = Integer.parseInt(value);
            }
    
            public String toString() {
                return String.format("%sms", 10 * value);
            }
    
            @Override
            public boolean equals(Object other) {
                return value == ((MillisecondValue) other).value;
            }
        }
    }
    
    
  3. In Topic: Read and save values different from the actual content in a JComboBox

    Posted 31 Mar 2015

    Right - so you're saying that the user can choose either 10 or 20 ms in each and every of the four boxes?
  4. In Topic: Read and save values different from the actual content in a JComboBox

    Posted 31 Mar 2015

    OK, that too is confusing. It doesn't make sense - your original question was about saving the chosen values into a text file. There would be no choice with such an arrangement.

    Let's take a step back from this. What is this meant to achieve? What is its purpose?
  5. In Topic: Read and save values different from the actual content in a JComboBox

    Posted 30 Mar 2015

    Sorry - i don't understand how that StringBuilder code fits in with saving and loading the combos.

My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private
Website URL:
Website URL  http://technojeeves.com

Comments

  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    reznum Icon

    19 Jul 2014 - 07:21
    Amazing guy
    Really appreciate your help :)
  2. Photo

    Nageshvk Icon

    28 Feb 2014 - 07:57
    can any body tell in Java SWINGS when do RepaintManager.scheduleProcessingRunnable() method is called? I am getting NPE while running the applet in JRE 1.7.51
  3. Photo

    john111 Icon

    27 Feb 2014 - 09:57
    any chance you can help me pleasee:
    http://www.dreamincode.net/forums/topic/341051-java-applet-creating-bar-chart-from-user-input/
  4. Photo

    trixt.er Icon

    30 Dec 2013 - 10:13
    *avatar image
  5. Photo

    trixt.er Icon

    30 Dec 2013 - 10:13
    Hey g00se why doesn't your avatar show up in your profile, but it does in your posts?
  6. Photo

    trixt.er Icon

    30 Dec 2013 - 08:12
    g00se be my friend! :)
  7. Photo

    nishakantsharma Icon

    07 Oct 2013 - 01:28
    how to remokve space between div tags
  8. Photo

    Anitush Icon

    21 Aug 2013 - 06:37
    hey could you help on my topic External Methods or error in code under Java pretty please. Thanks
  9. Photo

    Abomosa Icon

    20 Apr 2013 - 15:33
    can you help me more in my program
    http://www.dreamincode.net/forums/topic/319095-calculate-average-using-method/
  10. Photo

    Abomosa Icon

    20 Apr 2013 - 15:25
    http://www.dreamincode.net/forums/topic/319095-calculate-average-using-method/page__gopid__1839513&#entry1839513
  11. Photo

    raghav.naganathan Icon

    09 Dec 2012 - 09:41
    Congrats on the 1800 :)
  12. Photo

    raghav.naganathan Icon

    21 Nov 2012 - 04:48
    Dude, your rep just crossed the Hardy Ramanujan number(1729) :) Cheers :)
  13. Photo

    JeffBurnsRed Icon

    14 Nov 2012 - 07:10
    Thanks for all of your help
  14. Photo

    TheCodeNoob Icon

    28 Sep 2012 - 03:49
    You are useless and you should feel useless.
  15. Photo

    GameDesigner34 Icon

    31 Aug 2012 - 18:58
    Thank you so much for your help. I finished my program and you were the best at helping me.
  • (2 Pages)
  • +
  • 1
  • 2