Doubt in swing

Hai ,
Can I create a installer using swing?. If it is how to do that?
Refer me any link for the same.

DHURAI wrote:
Hai ,That's not an English word.
Can I create a installer using swing?. I'm not sure. What did you try? Where are you stuck?
If it is how to do that?Same way you create any other program.
Refer me any link for the same.
link

Similar Messages

  • A doubt in SWING event handling

    Hi all,
    I'm a beginner in JAVA studying SWING. I learned that if we want to handle an event for a event source(say JButton) we should implement corresponding Event Listener(say ActionListener) .
    I also understood that we should register the Listener with that event source.
    With that knowledge I tried this program
    import javax.swing.*;
    import java.awt.event.*;
    public class SimpleGui2 implements MouseListener,ActionListener {
       SimpleGui2 insGui;
       JButton button= new JButton("Click me");
         public static void main(String[] args) {
              SimpleGui2 gui = new SimpleGui2();
              gui.start();
       public void start() {
            JFrame frame = new JFrame();
            //button.addMouseListener(this);   
            //button.addActionListener(this);
            button.addActionListener(insGui);
            frame.getContentPane().add(button);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300,300);
            frame.setVisible(true);
       public void actionPerformed(ActionEvent ae) {
            button.setText("Triggered");
       public void mouseClicked(MouseEvent me) {
          button.setText("I have been clicked");
       public void mouseEntered(MouseEvent me) { }
       public void mouseExited(MouseEvent me) { }
       public void mousePressed(MouseEvent me) { }
       public void mouseReleased(MouseEvent me) { }  
    }but It's is not working as I expected.
    or precisely why when we clicked the actionPerformed/mouseClicked method is not invoked ?
    if i change the same with argument "this" it's working .
    I guess "this" refers to current object (which is also of type SimpleGui2 which implemented ActionListener)
    Can any one please clarify me what happens behind the scenes ?
    Thanks in advance

    first of all, you never initialize insGui. YOu just declare it, and never use it.
    SimpleGui2 insGui;However, you dont need it anyways. As you suspected, using 'this' when you add your actionListener is what you need.
    button.addActionListener(insGui);
    Can any one please clarify me what happens behind the scenes ?Well my professor always said it was 'black magic'. All I know is that you click a button with an event listener, and an event is fired doing whatever you want it to do. For example, if I want my event to print "Hey" then when I click the button, "Hey" is printed. Simple enough eh? You will probably find a better answer using Google though. It's amazing.

  • Doubt in swing-dragging

    How to a drag a component build in to the container. Suppose if I constructed a button within the panel it should be moved along with the mouse dragged event and on mouse released it should be placed in that area.In short how should I drag and drop the component?
    Thanks in advance
    javasans

    Try this:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    public class TestTextArea extends JFrame
         JScrollPane scrollPane;
         JTextArea textArea;
         ImageIcon image;
         public TestTextArea()
              JPanel panel = new JPanel();
              setContentPane( panel );
              panel.setLayout( new BorderLayout() );
              image = new ImageIcon("????.jpg");
              textArea = new JTextArea( "one two", 10, 30 )
                   public void paintComponent(Graphics g)
                        Point p = scrollPane.getViewport().getViewPosition();
                        g.drawImage(image.getImage(), p.x, p.y, null);
                        super.paintComponent(g);
              textArea.setOpaque(false);
              textArea.setFont( new Font("monospaced", Font.PLAIN, 12) );
              scrollPane = new JScrollPane( textArea );
              panel.add( scrollPane );
         public static void main(String[] args)
              TestTextArea frame = new TestTextArea();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • How to populate my input data into java bean through

    Hi,
    I have one doubt in swing how many ways we can populate the input properties(data fron gui screen) into my javabean object(Simple POJO)
    Thanks,
    Tuku

    Hi,
    I have one doubt in swing how many ways we can populate the input properties(data fron gui screen) into my javabean object(Simple POJO)
    Thanks,
    Tuku

  • Light weight && heavy weight

    hi
    i have on doubt in swing... awt are heavy weight && swing are light weight .awt are system dependedent ....iam right..
    if right System dependent in this sence java is plaftform independent
    so how is it possible..
    pls give me details
    regards
    kedar

    Light weight components: To draw the components the jvm takes the os routine.
    Heavy weight components: To draw the components the JVM takes its own routines.
    You can check this. If you draw the awt component in one os it gives the different layout in other os. But this is not in the case of swing.This is the main difference . That's why the main components in big project are done in swing.
    if in doubt please ask?
    javasans

  • Swing action events....a moment of doubt.

    Here I am, merrily hammering away on my first Swing application, listening to Pink Floyd "Shine On You Crazy Diamond" on my MP3 player, Diet Coke on hand, when my typing pauses and a fearful dread overtakes me.....
    I'm implementing the AbstractAction interface in one of my classes ("MainAction") because I want to share these events with a toolbar and some menu items. All well and good. However, how do you usually distinquish between different components when entering the actionPerformed method? I'll admit I know very little about the ActionEvent object, so if you want me to RTFM I won't hate you. :)
    At the moment I'm using the setActionCommand() to give the component its unique identity and then checking for this using: -
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("SOME_UNIQUE_STRING")) {
            // Do something here.
    }Its just that I've got a horrible idea that this is a really bad way to do it (based on no evidence at all, BTW). All the documentation I've read only deals with events for one button or something, while I'd like a way to distinquish between, say, two buttons.
    Don't get me wrong, the way I've done it works fine.....so I've no real problem. But if I'm doing things badly, I'd like to know now before I get too far down the development road with this.
    Thanks for any insights. :) Sorry if this is confusing between Actions and ActionListeners........I've only really used Actions at the moment and am not really at the stage where I have to use ActionListeners or anything like that just yet (Although I probably will get to that tomorrow).

    OR have a different Listener for each event source instead of just making the Panel implement ActionListener.
    That feels more object-oriented to me. "if/then/else" is usually a sign that you could rework the design to take better advantage of objects.
    The downside is that you have to write more objects. Clients of your code will have to look in more places to understand what you're doing.
    I like this approach because it decouples the GUI from what's done. If you give your UI class a constructor that takes the appropriate Listeners as arguments you can completely decouple the View from the Controller. I like that, too. Now you can keep the same UI and change what's done simply by passing in different Listeners.
    Just thought I'd offer this as another idea. It's not commonly presented in books.
    MOD

  • Doubt in creatin swing GUI

    First I created a JInterFrame as a Parent Component. From that i created an instance for JOptionPane .then i create a JInternalFrame by using JOptionPane's instance.
    Ex:
    JOptionPane optionPane = new JOptionPane(-,-,-,-,-) ;
    JInternalFrame internalFrame = optionPane.createInternalFrame(parentComponent, resources.getString("RecordingTitle"));
    here it.'s throwing error.RuntimeError
    I think it is getting error on casting of first argument - parentComponent
    without using null as a first argument what can i do ?
    pls explain with any example

    I just looked into the API...
    First of all, you should call a JOptionPane in a static way.
    Second, you have to define a parent frame/panel/whatever, where the OptionPane should appear.
    For example:
    int decision = JOptionPane.showInternalConfirmDialog(parent, "Do you agree?");
    if(decision == 0){ // ... }

  • How to create printable report from a swing app.

    Hi,
    I have googled quite a bit and have searched the forum extensively but haven't found answers to my questions.
    I have a small swing based application (that uses jtextfields, jbuttons, jlist, etc) that collects information from user
    and stores in some variables; which are like strings, integers, hashmap, etc.
    Now this information is to be formatted and is to be printed as a report.
    Formatted as in, some part of the collected text is to be printed in certain font and other in different color and so on.
    Also the report is to be printed on a paper leaving some space at left and at the top. That means margins need to be set.
    And before all info is to be sent to printer I need to display this information in some report viewer (preview).
    How can I format certain text and set margins? (Is there some Document kind of api which allows me to set margins, change font of certain text?)
    How should I display this text / information as a print preview? (Should I use jeditorpane / jtextpane ?)
    How should I send all the information to the printer? (What java api should be used for printing?)
    The data entered by the user is not saved / persisted to any database. It's to be sent to the printer after submit button is pressed on the swing app.
    Since there is no database I couldn't use jasper-reports.
    Following are links to all threads (not useful) I found when I searched for swing / print / report in the forum :
    http://forums.sun.com/thread.jspa?forumID=331&threadID=225351
    http://forums.sun.com/thread.jspa?forumID=57&threadID=576758
    http://forums.sun.com/thread.jspa?forumID=57&threadID=570629
    http://forums.sun.com/thread.jspa?forumID=1&threadID=489905
    http://forums.sun.com/thread.jspa?forumID=57&threadID=571093
    http://forums.sun.com/thread.jspa?forumID=257&threadID=138450
    http://forums.sun.com/thread.jspa?forumID=57&threadID=583150
    http://forums.sun.com/thread.jspa?forumID=57&threadID=5399572
    http://forums.sun.com/thread.jspa?forumID=57&threadID=579619
    http://forums.sun.com/thread.jspa?forumID=57&threadID=593199
    Help would be much appreciated.

    alan_mehio wrote:
    The simplest thing to do in your case is to load the file content into the JTextArea
    then to create the header and the footer if there is any from java.text.MessageFormat
    then you invoke the print method on the JTextArea instance object> Just let me know if you are face any furrher problem
    Alan Mehio,
    I have been able to set margins and get the printout just the way I want it (after some experiments / trial & error).
    But the problem is, parameters to paper.setImageableArea() are hard coded as in the example code below :
            System.out.println("print?");
            PrinterJob printJob = PrinterJob.getPrinterJob();
            if (printJob.printDialog()) {
                PageFormat pf = printJob.defaultPage();
                Paper paper = pf.getPaper();
                paper.setSize(8.5 * 72, 11 * 72);
                System.out.println("paper width : " + paper.getWidth());// expecting 612
                System.out.println("paper height : " + paper.getHeight());// expecting 792
                System.out.println("ImageableHeight : " + paper.getImageableHeight());
                System.out.println("imageable width : " + paper.getImageableWidth());
                System.out.println("ImageableX : " + paper.getImageableX());
                System.out.println("Imageable y : " + paper.getImageableY());
                //paper.setImageableArea(108, 144, paper.getWidth() - 108, paper.getHeight() - 144);
                paper.setImageableArea(222, 244, paper.getWidth() - 222, paper.getHeight() - 244);
                pf.setPaper(paper);
                printJob.setPrintable(jTextArea1.getPrintable(null, null), pf);
                try {
                    printJob.print();
                } catch (Exception ex) {
                    System.out.println("exception while printing...");
                    ex.printStackTrace();
            }In my case the left margin should be 1.5 inches (38.1mm) and top margin should be 2 inches (50.8 mm)
    Considering 72dpi printer for a A4 size page (8.5in X 11in), the parameters to paper.setImageableArea() should be
    (108, 144, paper.getWidth() - 108, paper.getHeight() - 144);
    But the printout leaves only 1inch for top and left margins.
    Here are o/p lines for method-call with above said params :
    paper width : 612.0
    paper height : 792.0
    ImageableHeight : 648.0
    imageable width : 468.0
    ImageableX : 72.0
    Imageable y : 72.0
    When I pass the following values I get text printed with desired margins on the paper but the above printlns remain exactly the same!
    paper.setImageableArea(222.4, 244, paper.getWidth() - 222.4, paper.getHeight() - 244);
    Although I have been able to achieve what I wanted to without using 3rd party libraries,
    I feel this hard coding of values isn't a good idea and leaves a doubt whether this will work on other systems with different printers.
    My question is, how to get these numbers correct every time? Is there a formula for obtaining these numbers?
    Also formatting of certain part of to-print text is something that is yet to be figured out.
    Thanks.

  • Please help: RMI and Swing/AWT issue

    Hi guys, I've been having a lot of trouble trying to get a GUI application to work with RMI. I'd appreciate any help. Here's the story:
    I wrote a Java application and its GUI using Netbeans. In a nutshell, the application is about performing searches. I am now at the point where I need exterior programs to use my application's search capabilities, thus needing RMI. Such exterior programs are to call methods currently implemented in my application.
    I implemented RMI, and got the client --> server communication working. However, the GUI just breaks. It starts outputting exceptions, gets delayed, doesn't update properly, some parts of it stop working.... basically hysterical behavior.
    Now take a look at this line within my server class:
    Naming.rebind("SearchProgram", mySearchProgram);
    If I take it out, RMI obviously does not work... but the application and its GUI work flawlessly. If I put it in, the RMI calls work, but the GUI's above symptoms occur again. Among the symptoms are null pointer exceptions which all look similar, are related to "AWT-EventQueue-0", and keep ocurring. Here's just snippet of the errors outputted:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.plaf.metal.MetalScrollBarUI.getPreferredSize(MetalScrollBarUI.java:102)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1615)
    at javax.swing.JScrollBar.getMinimumSize(JScrollBar.java:704)
    at javax.swing.ScrollPaneLayout.minimumLayoutSize(ScrollPaneLayout.java:624)
    at java.awt.Container.minimumSize(Container.java:1598)
    at java.awt.Container.getMinimumSize(Container.java:1583)
    at javax.swing.JComponent.getMinimumSize(JComponent.java:1697)
    at java.awt.BorderLayout.minimumLayoutSize(BorderLayout.java:634)
    at java.awt.Container.minimumSize(Container.java:1598)
    at java.awt.Container.getMinimumSize(Container.java:1583)
    at javax.swing.JComponent.getMinimumSize(JComponent.java:1697)
    at java.awt.BorderLayout.minimumLayoutSize(BorderLayout.java:634)
    at java.awt.Container.minimumSize(Container.java:1598)
    at java.awt.Container.getMinimumSize(Container.java:1583)
    at javax.swing.JComponent.getMinimumSize(JComponent.java:1697)
    at javax.swing.BoxLayout.checkRequests(BoxLayout.java:433)
    at javax.swing.BoxLayout.layoutContainer(BoxLayout.java:375)
    at java.awt.Container.layout(Container.java:1401)
    at java.awt.Container.doLayout(Container.java:1390)
    at java.awt.Container.validateTree(Container.java:1473)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validateTree(Container.java:1480)
    at java.awt.Container.validate(Container.java:1448)
    at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:379)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:113)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicMenuItemUI.getPreferredMenuItemSize(BasicMenuItemUI.java:400)
    at javax.swing.plaf.basic.BasicMenuItemUI.getPreferredSize(BasicMenuItemUI.java:310)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1615)
    at javax.swing.BoxLayout.checkRequests(BoxLayout.java:434)
    at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:251)
    at javax.swing.plaf.basic.DefaultMenuLayout.preferredLayoutSize(DefaultMenuLayout.java:38)
    at java.awt.Container.preferredSize(Container.java:1558)
    at java.awt.Container.getPreferredSize(Container.java:1543)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1617)
    at javax.swing.JRootPane$RootLayout.layoutContainer(JRootPane.java:910)
    at java.awt.Container.layout(Container.java:1401)
    at java.awt.Container.doLayout(Container.java:1390)
    at java.awt.Container.validateTree(Container.java:1473)
    at java.awt.Container.validate(Container.java:1448)
    at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:379)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:113)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    There are no complaints about anything within my code, it's all GUI related whenever I make a bind() or rebind() call.
    Again, any help here would be great... cause this one's just beating me.
    Thanks!

    Maybe you want to change that worker thread to
    not do RMI but anything else (dummy data) to see if it really is RMI, I doubt it, I think you are updating some structures that have to do with swing GUI and hence you will hang.
    Just check this out.

  • How to convert a .jad file to .class file in JAVA Swings.

    Hi all,
    Sorry for the interruption.I am also facing the same problem.I am using DEJDecompiler.But my application is not J2ME But J2EE.( a Swing application).I opened .class file and made some changes but I dont know how to convert into a .class file again.
    I tried saving .jad file to .java file.Then it is showing lot of errors in Eclipse Platform.I doubt if there are any errors in the .class file already,then how could the program would run.I put all the programs in the respective platforms only and then testing.It fails.
    (2) one more question,is if I do not need to disturb any existing coding and need to create a seperate java file which will do my customisation,then what should I do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.
    Thanks in advance
    With regds
    Satheesh.K

    I tried saving .jad file to .java file.Then it is
    showing lot of errors in Eclipse Platform.I doubt if
    there are any errors in the .class file already,then
    how could the program would run.I put all the programs
    in the respective platforms only and then testing.It
    fails.So who's Java program/library are you trying to steal?
    (2) one more question,is if I do not need to disturb
    any existing coding and need to create a seperate java
    file which will do my customisation,then what should I
    do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.Wow, you urgently need to steal someones program/library. The best person to give you advice urgently is the owner of the program/library you are trying to steal.
    Thanks in advancePlease don't thank me because I'm not going to help you!
    With regds
    Satheesh.K

  • Removing a window and adding a new one with swing.

    Hi,
    A friend of mine recently asked me to add a GUI for a small chat he made, so I thought I'd help him out. I've come across something that's troubled me in the past, and I could never find a solution. What I'm trying to do is make it so a log in window pops up (have that working alright) and then when you press sign in, it removes that window (log in) and adds the main chat window (have this fully functional, too).
    If someone could provide an example or point me in the direction of the proper API to look into, so that I don't have to look through them all, I'd be extremely grateful.
    Here's an SSCCE example:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.JTextPane;
    import javax.swing.ListSelectionModel;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.SwingUtilities;
    public class Gui extends JFrame {
         public static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
         public String sessionId;
         public int returnCode;
         public boolean recievedReturnCode;
         public boolean errorConnecting;
         public long lastActionDelay;
         private JScrollPane listScrollPane;
         private JList list;
         private JTextPane console;
         private JButton signInButton;
         private JScrollPane consoleScrollPane;
         private JTextField typingField;
         private DefaultListModel userList;
         private JButton sendButton;
         public static void main(String[] args) {
              try {
                   SwingUtilities.invokeAndWait(new Runnable() {
                        public void run() {
                             new Gui().setVisible(true);
              } catch (Exception e) {
                   e.printStackTrace();
         public Gui() {
              setResizable(false);
              setSize(500, 500);
              consoleScrollPane = new JScrollPane();
              console = new JTextPane();
              typingField = new JTextField();
              userList = new DefaultListModel();
              sendButton = new JButton();
              initializeLoginWindow();
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public void initializeLoginWindow() {
              setTitle("Login");
              signInButton = new JButton("Sign in");
              signInButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent evt) {
                        initializeChatWindow();
              signInButton.setBounds(5, 100, 75, 20);
              getContentPane().add(signInButton);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(new JPanel());
         public void initializeChatWindow() {
              consoleScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
              consoleScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
              consoleScrollPane.setViewportView(console);
              consoleScrollPane.setBounds(5, 5, 575, 350);
              console.setEditable(false);
              typingField.setEditable(true);
              typingField.setBounds(5, 360, 575, 25);
              list = new JList(userList);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            list.setSelectedIndex(0);
            list.setVisibleRowCount(5);
            listScrollPane = new JScrollPane(list);
              listScrollPane.setBounds(585, 5, 110, 350);
              sendButton.setText("Send");
              sendButton.setBounds(585, 360, 111, 25);
              getContentPane().add(consoleScrollPane);
              getContentPane().add(typingField);
              getContentPane().add(listScrollPane);
              getContentPane().add(sendButton);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(new JPanel());
    }Thanks in advanced!

    jduprez wrote:
    I've come across something that's troubled me in the past, and I could never find a solutionWhat is the problem?
    a log in window pops up (have that working alright)
    and then when you press sign in, it removes that window (log in) and adds the main chat window (have this fully functional, too).Hum, between what is working alright and what is already functional, I fail to see what is missing. Again, what is your problem/question?
    If someone could provide an example or point me in the direction of the proper API to look into, so that I don't have to look through them all, I'd be extremely grateful.
    [url http://download.oracle.com/javase/tutorial/uiswing/components/frame.html]JFrames and [url http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html]dialogs seem to show enough API usage to do that. Still, I stronlgy encourage you to read the whole Swing tutorial: http://download.oracle.com/javase/tutorial/uiswing/index.html
    Incase you didn't see the hyperlink above, here's the SSCCE link: http://www.mediafire.com/?e5e3ci3kbvickla
    The "S" in SSCCE stands for "Short" (or, depending on authors, "Simple"). Anyway, a decent SSCCE should fit within a forum post (between code tags please). The whole idea is to provide the simplest thing to people willing to help. No doubtful sites. No non-standard extensions.
    Best regards,
    The problem is that I cannot seem to remove the first pane, leaving the second one to be drawn on the current one.
    In reguards to SSCCE, I always thought it was just a short runnable class example, but I've added the class to the main post. I'll take a look at the API in a few as well.

  • Java Swing App hangs on socket loop

    H}ello everyone i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. I can't do that however since my app hangs when i look through the readLine() function to receive data and i dont know how to fix this error. The code is below.
    The doSocket() function is where the while loop is if anyone can help me with this i'd be very greatful.
    * GuiFrame.java
    * Created on August 13, 2008, 9:36 PM
    import java.net.*;
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author  brian
    public class GuiFrame extends javax.swing.JFrame {
        /** Creates new form GuiFrame */
        public GuiFrame() {
            initComponents();
        Socket client_sock = null;
        PrintWriter out = null;
        BufferedReader in = null;
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            convertButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Test Bot");
            convertButton.setText("Connect");
            convertButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    convertButtonActionPerformed(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()
                    .addGap(41, 41, 41)
                    .addComponent(convertButton)
                    .addContainerGap(42, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(convertButton)
                    .addContainerGap(26, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
    private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        if (convertButton.getText()=="Connect") {
                    String old;
                    try {
                        client_sock = new Socket("www.spinchat.com", 3001);
                        out = new PrintWriter(client_sock.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                    } catch (UnknownHostException e) {
                    } catch (IOException e) {
                try {
                    doSocket();
                } catch (IOException ex) {
                    Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        } else if (convertButton.getText()=="Disconnect") {
            out.println("e");
            out.close();
            try {
                client_sock.close();
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
    private void doSocket() throws IOException {
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String userInput;
        String old;
            while ((userInput = stdIn.readLine()) != null) {
                old = userInput;
                if (userInput != old) {
                    String proto = userInput.substring(0, 0);
                    if (proto == ":") {
                        out.println("{2");
                        out.println("BI'm a bot.");
                        out.println("aNICKHERE");
                        out.println("bPASSHERE");
                    } else if (proto == "a") {
                        convertButton.setText("Disconnect");
                        out.println("JoinCHannel");
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new GuiFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JButton convertButton;
        // End of variables declaration                  
    }Edited by: briansykes on Aug 13, 2008 9:55 PM
    Edited by: briansykes on Aug 13, 2008 9:56 PM

    >
    ..i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. >Is this intended as a GUId app? If so, I would stick to using a GUI for input, rather than reading from the command line (which when I run it, is the DOS window that jumps up in the BG - quite counterintuitive). On the other hand, if it is intended as a non-GUId or headless app., it might be better to avoid any use of JComponents at all.
    My edits stick to using a GUI.
    Other notes:
    - String comparison should be done as
    s1.equals(s2)..rather than..
    s1 == s2- Never [swallow exceptions|http://pscode.org/javafaq.html#stacktrace] in code that does not work.
    - Some basic debugging skills are well called for here, to find where the program is getting stuck. When in doubt, print out!
    - What made you think that
    a) a test of equality on a member against which you had just set the value to the comparator, would logically lead to 'false'?
    old = userInput;
    if (userInput != old) ..b) A substring from indices '0 thru 0' would provide 1 character?
    String proto = userInput.substring(0, 0);
    if (proto == ":") ..
    >
    ..if anyone can help me with this i'd be very greatful.>Gratitude is often best expressed through the offering of [Duke Stars|http://wikis.sun.com/display/SunForums/Duke+Stars+Program+Overview].
    * GuiFrame.java
    * Created on August 13, 2008, 9:36 PM
    import java.net.*;
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    * @author  brian
    public class GuiFrame extends JFrame {
        /** Creates new form GuiFrame */
        public GuiFrame() {
            initComponents();
        Socket client_sock = null;
        PrintWriter out = null;
        BufferedReader in = null;
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            convertButton = new JButton();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("Test Bot");
            convertButton.setText("Connect");
            convertButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    convertButtonActionPerformed(evt);
            GroupLayout layout = new GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(41, 41, 41)
                    .addComponent(convertButton)
                    .addContainerGap(42, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(convertButton)
                    .addContainerGap(26, Short.MAX_VALUE))
            pack();
            setLocationByPlatform(true);
        }// </editor-fold>
    private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {
        if (convertButton.getText()=="Connect") {
                    String old;
                    try {
                        System.out.println( "Connect start.." );
                        client_sock = new Socket("www.spinchat.com", 3001);
                        out = new PrintWriter(client_sock.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                        System.out.println( "Connect end.." );
                    } catch (UnknownHostException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                try {
                    doSocket();
                } catch (IOException ex) {
                    Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        } else if (convertButton.getText()=="Disconnect") {
            out.println("e");
            out.close();
            try {
                client_sock.close();
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        private void doSocket() throws IOException {
            System.out.println( "doSocket start.." );
            String userInput;
            String old;
            userInput = JOptionPane.showInputDialog(this, "Send..");
            while(userInput!=null && userInput.trim().length()>0) {
                System.out.println( "doSocket loop 1.." );
                String proto = userInput.substring(0, 1);
                System.out.println("proto: '" + proto + "'");
                if (proto.equals(":")) {
                    System.out.println("Sending data..");
                    out.println("{2");
                    out.println("BI'm a bot.");
                    out.println("aNICKHERE");
                    out.println("bPASSHERE");
                } else if (proto.equals("a")) {
                    convertButton.setText("Disconnect");
                    out.println("JoinCHannel");
                userInput = JOptionPane.showInputDialog(this, "Send..");
            System.out.println( "doSocket end.." );
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new GuiFrame().setVisible(true);
        // Variables declaration - do not modify
        private JButton convertButton;
        // End of variables declaration
    }

  • Swing or JSP/Struts application?

    I'm deploying an application for a public hospital in Argentina and i have doubts about the framework to use.
    The application will be used in very old computers (pentium I/II or older) but will count with a good server (bought specifically for this use).
    This limitation of hardware also has made me rethink the election of the framework of persistence. It would be appropriate to use hibernate?
    I'll appreciate if you can help me with this decisions.
    Adriana

    To give you a good answer I would need a lot more information, but right now it sounds like your best bet is to use JSP. Here are two enormous reasons why:
    1) You will not have to deploy any software at the client end - as long as they have a web browser they will be able to connect. They do not even need Java support. This has several related advantages, including that you will never have to deal with "updating" the clients - you can change the code on your end freely.
    2) The total amount of work you put into it is probably going to be a lot less. Since you are just using HTML and not writing a GUI proper, it will be a lot easier.
    The main reason you might discover that you do NOT want to use JSP is that it limits your functionality. For example, if you decide you need an interactive chat room you are going to end up coming back to Swing and deploying either an applet, Java Web Start app, or standalone application... unless you do not mind it being a really crappy chat room.
    Drake

  • Create a swing application with reflection

    Hi folks, I'm seeing the possibility to create a application like eclipse wich loads the classes in a folder and builds the application , but I have a doubt, how organize the components in application , how I will add a component in a menu, how I will build the hierarchy , separating menus,panel and buttons , anyone have idea ?
    Thanks .

    1) Use JEditorPane
    2) Need to Highlight syntax
    3) Need to show lines
    check out these links
    coweb.cc.gatech.edu/mediaComp-plan/uploads/95/JESGutter.1.java
    http://javaalmanac.com/egs/javax.swing.text/style_HiliteWords2.html
    Now to popup
    setLayout for the JEditorPane to null
    You will have one JComboBox /or popup with all the properties and methods
    of the class.
    now add that JComboBox to JEditorPane
    You can get the position of the dot by using
    Point point = editorPane.getCaret().getMagicCaretPosition();
    popupMenu.show( jEditorPane,
    (int)point.getX(),
    (int)point.getY());
    Here you can show JComboBox too. (Absolute positioning).
    Now as you need to use JEditorPane implement DocumentListener on it.
    Using caret listener you can get the current word.
    You can use getClass() for that. Add all the methods and properties in JComboBox or Popup.
    As for other properties such as saving keywords, search, 'files opened' etc.
    you can use xml.

  • Doubt in AWT

    Hi,
    I have a doubt in AWT. We needed a custom title bar for our dialogs. Since we are using JDK 1.3(Actually J2me personal profile 1.0), its not possible to use setUndecorated() method. Hence we made a custom dialog class extending the java.awt.Window class. Now when I add a button to the dialog, the button isn't generating any ActionEvent on pressing the space-bar over the button even though its generating the KeyEvent. The ActionEvent gets generated on clicking the button with the mouse. What could be the issue? This issue doesn't happen if I extend the Dialog class.
    With Regards,
    Anand

    Light weight components: To draw the components the jvm takes the os routine.
    Heavy weight components: To draw the components the JVM takes its own routines.
    You can check this. If you draw the awt component in one os it gives the different layout in other os. But this is not in the case of swing.This is the main difference . That's why the main components in big project are done in swing.
    if in doubt please ask?
    javasans

Maybe you are looking for

  • How do you clear the Camera RAW settings?

    When opening a photo in Bridge, the photo opens in it's original state but then Bridge quickly applies settings to it and it looks darker. How do I stop this from happening? Can I easily turn it off and on? I tried Edit>Apply Camera RAW Settings>Clea

  • Reference field in the smartform

    hello, can you help me to specify reference field in smartform. That means, i had created the structure in which there is a field VEMNG for which the reference field is VEMEH from reference table VEPO. Then i had written the program and created the i

  • ALTERNATE COLOR SCHEME TRICK FOR MACS

    Hey guys. Just found a little built in "trick" that is kinda cool. Press Control, Option, Command and 8 at the same time on your keyboard. The color scheme of your monitor will go into negative color - all colors are reversed here - whites are now bl

  • Wireless router console unable to be viewed

    I have a G router that I never have issues with until now.   I jested installed windows 7 on all my machines and after doing this I am unable to get to the Linksys Console.   I have tried IE 8 and Firefox but still no luck.   I first thought it was a

  • Does Import/Export Utility check for Block corruption?

    Hi All, Just a quick question I have is does Import/Export Utiligy check for any block corruption while importing or exporting? If yes then does it do automatically or we have do set some parameter explicitly. I am using oracel version 9.2.0.6. Thx i