Help needed on a chat program..............

Somebody please help me. I can't seem to get my client/server program to work well. The problem is that when a client sends a message to another client, the other client doesn't receive that message. Instead, the server and the client that sent the message are the ones that receive the message.
Here is the server code that processes the messages:
BufferedReader incomeReader = null;
PrintWriter outWriter = null;
try {
     incomeReader = new BufferedReader(new InputStreamReader(incomingSocket.getInputStream()));
outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);
}catch (Exception e) {
          System.out.println("error handling a client: " + e);
System.exit(-1);
line = incomeReader.readLine();
outWriter.println(line);
outWriter.flush();
Well, i hope somebody will be able to help....

incomeReader = new BufferedReader(new InputStreamReader(incomingSocket.getInputStream()));
outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);Quite what you programmed. "incomingSocket" sends the message and gets it back.

Similar Messages

  • Help needed with a chat program

    Hi everyone! i'm busy with a client/server chat program. I'm really stuck because i can't seem to get the messages from one client to show on the other client's screen.
    If one client sends a message to another client, the server receives the message, but the second client does not receive the message.
    Here is the server code that sends messages to the clients:
    BufferedReader incomeReader = null;
    PrintWriter outWriter = null;
    try {
         incomeReader = new BufferedReader(new InputStreamReader (incomingSocket.getInputStream()));
    outWriter = new PrintWriter(incomingSocket.getOutputStream(),true);
    }catch (Exception e) {
              System.out.println("error handling a client: " + e);
    System.exit(-1);
    line = incomeReader.readLine();
    textArea.append(line + "\n");               
    outWriter.println(line);
    The server is suppose to put the message it receives on the text area on the server screen, and then send the message to all clients connected to it.
    I hope somebody will be able to help me...

    The code posted just sends any data it receives back to the person who sent it. To get it to work there, you probably should flush after the println. I believe your mother taught you always to flush. It seems you have forgotten.

  • Help me in my chat program please

    hi,
    Im doing chat program same as yahoo messenger using Java.Please help me in creating rooms....so that it will be a great help for me to finish my project..
    Thanks in advance
    PadmaPriya.

    hi,
    Actually i have a common room in which people enter through a login screen and chat...it shows the user list .
    what i want to do is i want to add a combo box in the login screen with mulitple rooms...the user should select rooms and then must be able to chat....in their rooms...
    so that many rooms would function at a time..and people will be chatting correspondingly....can u please help me in doing that...
    Thanks in advance
    PadmaPriya.

  • Help need on ALV Report Program

    Hi all.....
    im facing problem in the following code....it shows 'No records found' (as same as my coding generated)whenever i give wrong vendor no:(lifnr), but if i gives the correct one(as in table lfa1)...it shows Runtime error as <b>"the occupied line length in the program text must not exceed the width of the internal table"</b>..
    pls verify...
    just go thru my code and revert me the feedback of what i did wrong and pls i dont want any example codes from u guys since i've seen so much and couldnt solve it with that...
    hope u understand......what i need
    Rewards based on the above reuirements....only
    *******************************CODING***********************************************
    REPORT ZALV_MERGE.
    TABLES:lfa1.
    DATA:BEGIN OF itab OCCURS 100,
    lifnr LIKE lfa1-lifnr,
    land1 LIKE lfa1-land1,
    name1 LIKE lfa1-name1,
    ort01 LIKE lfa1-ort01,
    regio LIKE lfa1-regio,
    sortl LIKE lfa1-sortl,
    END OF itab.
    data: i_repid like sy-repid,
          i_tabix like sy-tabix.
    TYPE-POOLS: slis.
    DATA: fcat TYPE slis_t_fieldcat_alv.
    SELECT-OPTIONS: LIFNR FOR LFA1-LIFNR.
    SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE itab WHERE lifnr IN LIFNR.
    clear i_tabix.
    describe table itab lines i_tabix.
    if i_tabix lt 1.
    write:/ 'No materials found'.
    exit.
    endif.
    i_repid = sy-repid.
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = i_repid
       I_INTERNAL_TABNAME           = 'ITAB'
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_INCLNAME                   = I_REPID
      I_BYPASSING_BUFFER           =
      I_BUFFER_ACTIVE              =
      CHANGING
        CT_FIELDCAT                  = fcat
      EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 2
       OTHERS                       = 3.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = i_repid
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
       I_STRUCTURE_NAME               = 'ITAB'
      IS_LAYOUT                      =
       IT_FIELDCAT                    = fcat
       I_SAVE                         = 'A'
      TABLES
        T_OUTTAB                       = ITAB
    EXCEPTIONS
       PROGRAM_ERROR                  = 1
       OTHERS                         = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Hi,
    think inthis program in the function module REUSE_ALV_FIELDCATALOG_MERGE
    in exporting parameter you are using -->
    I_INTERNAL_TABNAME = <itab_name>
    this <itab_name> is not like any physical structure .So make a structure through SE11 like <itab_name>.
    u have to create a structure in SE11 with the fields, and then pass that structure into the REUSE_ALV_FIELDCATALOG_MERGE , in the parameter
    I_internal_tabname = ' structure name '.
    even though u create a structure, u need to pass it to the table parameter.
    then it will work.
    Otherwise manually build the fieldcatalog.
    find the following code as an example.
    DATA : l_pos TYPE i VALUE 1.
      ist_fieldcat-fieldname = 'POSID'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 24.
      ist_fieldcat-col_pos   = l_pos.
    ist_fieldcat-ddictxt = 'L'.
      ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Appropriation Request Number'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
      l_pos = l_pos + 1.
      ist_fieldcat-fieldname = 'TXT04'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 4.
      ist_fieldcat-col_pos   = l_pos.
      ist_fieldcat-ddictxt = 'L'.
    ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Status'.
      ist_fieldcat-EMPHASIZE = 'C400'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
      l_pos = l_pos + 1.
      ist_fieldcat-fieldname = 'UDATE'.
      ist_fieldcat-tabname   = 'IT_FINAL'.
      ist_fieldcat-outputlen = 8.
      ist_fieldcat-col_pos   = l_pos.
      ist_fieldcat-ddictxt = 'L'.
      ist_fieldcat-key = 'X'.
      ist_fieldcat-seltext_l = 'Status Date'.
    IST_FIELDCAT-EMPHASIZE = 'C600'.
      APPEND ist_fieldcat.
      CLEAR ist_fieldcat.
    <i><b>Reward point if find helpful
    Debjani</b></i>

  • Help needed in Logical Database Programming

    Hello Gurus,
    I am working on a Report on ASSET ACTIVITY BY DATE RANGE .
    The program is copied from std. program S_ALR_87011990.
    The above std. program displays for the whole financial year. This is modified for a particalar period range in the new leveraged program.
    My question is in the below code.
    We are fetching data using LDB ADA. The statement "GET anlcv" works fine here, I mean Sy-subrc is 0 and anlcv structure has some data in it.
    When it comes to statement "GET anepv" in the below code, we are not getting any data into that structure and sy-subrc NE 0. Then it is skipping all the get statements and directly going to statement " PERFORM abga_simulieren.".
    My logic lies in between this Get statement and the perform statement. When i see it in debugging mode my statement is not executed at all.
    What needs to be done. Please anyone help me.
    GET anlcv.
    CHECK select-options.
    MOVE anlcv TO sav_anlcv.
    GET anepv.
    CHECK select-options.
    Nur Bewegungen des Jahres des Berichtsdatums durchlassen.
    CHECK anepv-bzdat GE sav_gjbeg.
    CHECK anepv-bzdat IN so_bzdat. "Added for SIR-3132
    Bewegungen in SAV_ANEPV sammeln.
    MOVE anepv TO sav_anepv.
    APPEND sav_anepv.
    GET anlb LATE.
    Check auf Bestandskonto bei Gruppensummen erst hier, wegen
    fehlender Abgänge/Umbuchungen
    IF NOT summb IS INITIAL.
    IF NOT anlav-ktansw IN so_ktanw.
    REJECT 'ANLAV'.
    ENDIF.
    ENDIF.
    ANLCV aus Save-Area zurueckholen.
    CHECK NOT sav_anlcv-anln1 IS INITIAL.
    MOVE sav_anlcv TO anlcv.
    Abg-Simu: Abgang simulieren.
    PERFORM abga_simulieren.
    Promise to reward points
    Regards
    Mac

    1) delete line  CHECK anepv-bzdat ge sav_gjbeg.
    2) test with an asset , which has movements (purchases) in your intervall so_bzdat.
    otherwise post a movement (e.g. transaction type 100) with tcode abzon
    A.

  • Help neede in changing standard program CN41

    Dear all,
    I am working on a requirement in PS module.
    The requirement is I need to copy the standard program RCNST000 of CN41 and I need to add some extra fields.
    Here in initial display project object, project object.
    when I select duration and Order cost plan 000 from the list It will display duration and order cost plan in the report.
    My requirement is when they select that I need to display cost per day and cost for currect month.
    Can anybody help me.
    Thnaks and regards
    Anil

    Dear all,
    I am working on a requirement in PS module.
    The requirement is I need to copy the standard program RCNST000 of CN41 and I need to add some extra fields.
    Here in initial display project object, project object.
    when I select duration and Order cost plan 000 from the list It will display duration and order cost plan in the report.
    My requirement is when they select that I need to display cost per day and cost for currect month.
    Can anybody help me.
    Thnaks and regards
    Anil

  • Some help needed for shopping calculator program

    Hi. I would like to thank you in advance for helping me. At the moment I am pretty much stuck. I don't know how to add the input using 'while loop'. This is what I'm suppose to do:
    Write a program called ShoppingCalculator.java that allows the user to enter the prices of several items they have bought and then tells them the total amount. The user can enter the prices for as many items as they want, until they click Cancel. The program should then output the total amount they spent, in a message dialog box. Use pounds for all the amounts.
    So far I have written:
    import javax.swing.JOptionPane;
    public class ShoppingCalculator
        public static void main(String[] args)
                boolean done = false;
                double amount;
                String input;
                while (!done)
                        input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
                        amount = Double.parseDouble (input);
                if (done = true)
                        JOptionPane.showMessageDialog (null, "You spent a total amound of £" + amount  );
    }Sorry if the code doesn't make much sense cause I've been changing the code around so many times that.
    At one point when I was playing around with the code, I manage to make the input dialog loop nicely but when I pressed cancel, the message dialog only output the last input I put in. What I'm really stuck here is I need to know how to add the input when using 'while loop' and is it correct to use the IF Statement on this program. Please give me some advice on how to and I will try to work on it again.

    Ok. I have edit the code and this is what it looks like:
    import javax.swing.JOptionPane;
    public class ShoppingCalculator
        public static void main(String[] args)
                boolean done = false;
                double amount;
                String input;
                double total = 0;
                while (!done)
                        input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
                        amount = Double.parseDouble (input);
                            if (input == null)
                                        total = total + amount;
                                        JOptionPane.showMessageDialog (null, "You spent a total amound of " + total  );
    }I created another variable (total) and it even compiled. The only problem I have now is the message dialog wouldn't show at the end. When I press cancel and nothing happen. This is what I get on my output command window:
    Exception in thread "main" java.lang.NullPointerException
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
    at java.lang.Double.parseDouble(Double.java:510)
    at ShoppingCalculator.main(ShoppingCalculator.java:23)
    Java Result: 1
    Anything that isn't right here?

  • Help Needed on a java program

    I am very new to java and our teacher has given us a program
    that i am having quite a bit of trouble with. I was wondering if anyone could help me out.
    This is the program which i have bolded.
    {You will write a Java class to play the TicTacToe game. This program will have at least two data members, one for the status of the board and one to keep track of whose turn it is. All data members must be private. You will create a user interface that allows client code to play the game.
    The user interface must include:
    � Boolean xPlay(int num) which allows x to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean oPlay(int num) which allows o to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean isEmpty(int num) will check to see if the square labeled by num is empty.
    � Void display() which displays the current game status to the screen.
    � Char whoWon() which will return X, O, or C depending on the outcome of the game.
    � You must not allow the same player to play twice in a row. Should the client code attempt to, xPlay or oPlay should print an error and do nothing else.
    � Also calling whoWon when the game is not over should produce an error message and return a character other than X, O, or C.
    � Client code for the moment is up to you. Assume you have two human players that can enter the number of the square in which they want to play.
    Verifying user input WILL be done by the client code.}

    This is the program which i have bolded.Hmmm, that doesn't look like any programming language I've ever seen. I guess you have the wrong forum here, because it isn't Java.
    That looks like a natural-language programming language that directly understands a homework assignment. Either that, or you really did just post the assignment. You wouldn't have done that though, right?

  • Help:something whin a Chat program

    source code below:
    public class ChatServer extends UnicastRemoteObject implements ... {
    ClientCallbacks cl = null;
    public void connect(ClientCallbacks cl) throws RemoteException {
    this.cl = cl;
    public void sendMessage(String msg) throws RemoteException {
    cl.receiveMessage(msg);
    public class Client extends JFrame implements ClientCallbacks{
    ChatServer remoteServer;
    remoteServer.connect(this);
    TextArea messages = new TextArea(10,50);
    public void receiveMessage(String msg) throws java.rmi.RemoteException
         // Complete callback implementation
         messages.setText(msg);
    //     ((JFrame)callbacks).show();
    public interface ClientCallbacks extends java.rmi.Remote
    public void receiveMessage(String msg) throws java.rmi.RemoteException;
    compiling is OK! running is OK!
    the callbacks cl.receiveMessage really run, but it is running on the server side and not on the client side.
    so, the TextArea messages on the client side can't be changed.
    if the statement ((JFrame)callbacks).show() which is been comment above is active, a gui will be display
    on the server side. I want not that.
    the remoteServer object is been get from Naming.lookup(...).
    and, the cl is been transfered by the method remoteServer.connect(cl);
    I want the cl.receiveMessage(...) can change the TextArea messages on the client side. It maybe need that
    method receiveMessage(...) performed on client side, which is not same as now.
    maybe, in the program, the object cl is been serialized to the server and run on the server side, it isn't same as that of the remoteServer.
    I want it performed like remoteServer, and can change the client. What should I do?

    Maybe, that is really a problem, didn't it?

  • Help needed with a paint program

    Hi, I am writing a program to work as a paint application. I have all the necessary buttons. One of my buttons needs to be able to add a small image to the painting frame by clicking the mouse onto the screen...for example, to display a picture of a house, I click the house button which then puts my house picture onto the scribble panel wherever I click the mouse. My problem is that I am new to java and I am stuck on how I can do this. I have put all the code on here which I have. If any one knows the code which I can add to make this work I would very much appreciate it as it is driving me insane!
    Many thanks....
    CODE "DrawingTools.java".............................
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class DrawingTools {
    public static void main (String [] args) {
         Toolkit tk = Toolkit.getDefaultToolkit(); // get system dependent information
    Dimension dim = tk.getScreenSize(); // encapsulate width and height of system
    JFrame f = new DrawingToolFrame();
    f.setSize(800, 550);
    f.setTitle("Drawing Tool v1.10");
    f.setIconImage(tk.getImage("Paint.gif"));
    f.setVisible(true);
    f.setResizable(false);
    class DrawingToolFrame extends JFrame implements ActionListener {
    private JCheckBox checkNormal, checkBold, checkDotted, checkSpray;
    // private JRadioButton orBlack, orBlue, orRed, orYellow, orNormal, orBold, orDotted, orSpray;
    private JButton boldButton, dottedButton, sprayButton;
    private JButton blackButton, blueButton, yellowButton, redButton, greenButton, houseButton, tvButton, starButton;
    private ScribblePanel scribblePanel;
    private JButton scribbleButton, undoButton, newButton, quitButton;
    private JMenuItem newItem, quitItem, undoItem, houseItem, tvItem, starItem,/* normalItem,*/ boldItem, dottedItem, sprayItem, blackItem, blueItem, redItem, yellowItem, greenItem;
    public DrawingToolFrame() {
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    Container contentPane = getContentPane();
    JMenuBar menuBar = new JMenuBar();
         setJMenuBar(menuBar);
         JMenu fileMenu = new JMenu("File");
         newItem = new JMenuItem("New");
         newItem.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
         newItem.addActionListener(this);
         fileMenu.add(newItem);
         quitItem = new JMenuItem("Quit");
         quitItem.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to Quit short-cut
         quitItem.addActionListener(this);
         fileMenu.add(quitItem);
         menuBar.add(fileMenu);
         JMenu editMenu = new JMenu("Edit");
         undoItem = new JMenuItem("Undo");
         undoItem.addActionListener(this);
         editMenu.add(undoItem);
         menuBar.add(editMenu);
         JMenu shapeMenu = new JMenu("Shape");
         houseItem = new JMenuItem("House");
         houseItem.addActionListener(this);
         shapeMenu.add(houseItem);
         tvItem = new JMenuItem("Television");
         tvItem.addActionListener(this);
         shapeMenu.add(tvItem);
         starItem = new JMenuItem("Star");
         starItem.addActionListener(this);
         shapeMenu.add(starItem);
         menuBar.add(shapeMenu);
    JMenu optionMenu = new JMenu("Option");
    JMenu lineMenu = new JMenu("Line");
         optionMenu.add(lineMenu);
              //normalItem = new JMenuItem("Normal");
              //normalItem.addActionListener(this);
              //lineMenu.add(normalItem);
              boldItem = new JMenuItem("Bold");
              boldItem.addActionListener(this);
              lineMenu.add(boldItem);
              dottedItem = new JMenuItem("Dotted");
              dottedItem.addActionListener(this);
         lineMenu.add(dottedItem);
         sprayItem = new JMenuItem("Spray");
         sprayItem.addActionListener(this);
         lineMenu.add(sprayItem);
         JMenu colourMenu = new JMenu("Colour");
         optionMenu.add(colourMenu);
              blackItem = new JMenuItem("Black");
              blackItem.addActionListener(this);
              colourMenu.add(blackItem);
              blueItem = new JMenuItem("Blue");
              blueItem.addActionListener(this);
              colourMenu.add(blueItem);
              redItem = new JMenuItem("Red");
              redItem.addActionListener(this);
         colourMenu.add(redItem);
         yellowItem = new JMenuItem("Yellow");
         yellowItem.addActionListener(this);
         colourMenu.add(yellowItem);
         greenItem = new JMenuItem("Green");
                   greenItem.addActionListener(this);
         colourMenu.add(greenItem);
         menuBar.add(optionMenu);
    JPanel p = new JPanel();
    ImageIcon scribbleIcon = new ImageIcon("Scribble.gif");
    scribbleButton = new JButton("Scribble", scribbleIcon);
    scribbleButton.setMnemonic(KeyEvent.VK_S); //add Alt-S to Undo short-cut
    scribbleButton.setToolTipText("Click this button and you can draw free hand lines.");
    p.add(scribbleButton);
    //scribbleButton = addJButton("Scribble", p);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon undoIcon = new ImageIcon("Undo.gif");
    undoButton = new JButton("Undo", undoIcon);
    undoButton.setMnemonic(KeyEvent.VK_U); //add Alt-U to Undo short-cut
    undoButton.setToolTipText("Undo the last step");
    p.add(undoButton);
    //undoButton.addActionListener(this);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon newIcon = new ImageIcon("New.gif");
    newButton = new JButton("New", newIcon);
    newButton.setMnemonic(KeyEvent.VK_N); //add Alt-N to New short-cut
    newButton.setToolTipText("Make a new Drawing");
    p.add(newButton);
    p.add(Box.createHorizontalStrut(20));
    ImageIcon quitIcon = new ImageIcon("Door.gif"); //add icon to button
    quitButton = new JButton("Quit", quitIcon);
    quitButton.setMnemonic(KeyEvent.VK_Q); //add Alt-Q to exit short-cut
    quitButton.setToolTipText("Click to Exit");
    p.add(quitButton);
    undoButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.undo();}});
    scribbleButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.repaint();}});
    newButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    scribblePanel.repaint();}});
    quitButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    System.exit(0);}});
    contentPane.add(p, "South");
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createVerticalStrut(10));
    ImageIcon boldIcon = new ImageIcon("Bold.gif"); //add icon to button
    boldButton = new JButton("Bold", boldIcon);
    p.add(boldButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon dottedIcon = new ImageIcon("Dotted.gif"); //add icon to button
    dottedButton = new JButton("Dotted", dottedIcon);
    p.add(dottedButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon sprayIcon = new ImageIcon("Spray.gif"); //add icon to button
    sprayButton = new JButton("Spray", sprayIcon);
    p.add(sprayButton);
    /*     ButtonGroup groupA = new ButtonGroup();
         p.add(Box.createVerticalStrut(20));
         orNormal = addJRadioButton("Normal", true, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orBold = addJRadioButton("Bold", false, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orDotted = addJRadioButton("Dotted", false, groupA, p);
         p.add(Box.createVerticalStrut(20));
         orSpray = addJRadioButton("Spray", false, groupA, p);*/
    contentPane.add(p, "East");
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(Box.createVerticalStrut(10));
    ImageIcon dIcon = new ImageIcon("Black.gif"); //add icon to button
    blackButton = new JButton("Black", dIcon);
    p.add(blackButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon eIcon = new ImageIcon("Blue.gif"); //add icon to button
    blueButton = new JButton("Blue", eIcon);
    p.add(blueButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon fIcon = new ImageIcon("Red.gif"); //add icon to button
    redButton = new JButton("Red", fIcon);
    p.add(redButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon gIcon = new ImageIcon("Yellow.gif"); //add icon to button
    yellowButton = new JButton("Yellow", gIcon);
    p.add(yellowButton);
    p.add(Box.createVerticalStrut(10));
    ImageIcon hIcon = new ImageIcon("Green.gif"); //add icon to button
    greenButton = new JButton("Green", hIcon);
    p.add(greenButton);
    p.add(Box.createVerticalStrut(30));
    ImageIcon houseIcon = new ImageIcon("house.gif");
    houseButton = new JButton("House", houseIcon);
    houseButton.setToolTipText("Click to add a house in the picture!");
    p.add(houseButton);
    //houseButton = addJButton("House", p);
    p.add(Box.createVerticalStrut(10));
    ImageIcon tvIcon = new ImageIcon("tv.gif");
    tvButton = new JButton("Television", tvIcon);
    tvButton.setToolTipText("Click to add a Television in the picture!");
    p.add(tvButton);
    //tvButton = addJButton("Television", p);
    p.add(Box.createVerticalStrut(10));
    ImageIcon starIcon = new ImageIcon("star.gif");
    starButton = new JButton("Star", starIcon);
    starButton.setToolTipText("Click to add stars in the picture!");
    p.add(starButton);
    //starButton = addJButton("Star", p);
    contentPane.add(p, "West");
    scribblePanel = new ScribblePanel();
    contentPane.add(scribblePanel, "Center");
    private JButton addJButton(String text, Container container) {
    JButton button = new JButton(text);
    container.add(button);
    return button;
    private JRadioButton addJRadioButton(String text, boolean on, ButtonGroup group, Container container) {
    JRadioButton button = new JRadioButton(text, on);
    group.add(button);
    container.add(button);
    return button;
    public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source instanceof JMenuItem) {
    String arg = e.getActionCommand();
    if (arg.equals("Undo"))
    scribblePanel.undo();
    else if (arg.equals("New"))
    scribblePanel.repaint();
    else if (arg.equals("Quit"))
    System.exit(0);
    }

    The code posted just sends any data it receives back to the person who sent it. To get it to work there, you probably should flush after the println. I believe your mother taught you always to flush. It seems you have forgotten.

  • Help needed on where install program places UPK Library

    I installed UPK Developer (Version 11.1) on my laptop in order to get familiar with it before an upcoming project. However, I cannot get past the Add Profile dialog box as I don't know where the Install program placed the Library on my computer. Any help would be appreciated. Thanks.

    Do you remember if you installed UPK as a single user or multi-user configuration? The multi-user setup requires the pathname to a library on an external server when you launch UPK. You might want to reinstall UPK and make sure you chose the single user option. I'm not 100% sure, but it sounds like that might be the issue.

  • Help needed, new to java programming

    hi,
    I have craeted a Frame with some check boxes and button called "button1".
    Can anyone tell me how can i count the number of CHECKED check boxes so that when i press the button1 in my code it should display the result as number of checked check boxes divided by total number of check boxes. It should display the result in a textfield here RESULT textfield in my code
    Thanks in advance ...i am sending the code i have written so far....
    public class Frame extends java.awt.Frame {
        /** Creates new form Frame */
        public Frame() {
            initComponents();
            setSize(600, 600);
        /** 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.
        private void initComponents() {
            buttonGroup1 = new javax.swing.ButtonGroup();
            checkbox1 = new java.awt.Checkbox();
            checkbox2 = new java.awt.Checkbox();
            checkbox3 = new java.awt.Checkbox();
            button1 = new java.awt.Button();
            textField1 = new java.awt.TextField();
            setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            checkbox1.setLabel("checkbox1");
            add(checkbox1);
            checkbox1.setBounds(160, 50, 84, 20);
            checkbox2.setLabel("checkbox2");
            add(checkbox2);
            checkbox2.setBounds(160, 70, 84, 20);
            checkbox3.setLabel("checkbox3");
            add(checkbox3);
            checkbox3.setBounds(160, 90, 84, 20);
            button1.setLabel("button1");
            button1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    button1ActionPerformed(evt);
            add(button1);
            button1.setBounds(150, 180, 57, 24);
            textField1.setText("Result");
            textField1.setName("Result");
            add(textField1);
            textField1.setBounds(260, 180, 44, 20);
            pack();
        private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new Frame().show();
        // Variables declaration - do not modify
        private java.awt.Button button1;
        private javax.swing.ButtonGroup buttonGroup1;
        private java.awt.Checkbox checkbox1;
        private java.awt.Checkbox checkbox2;
        private java.awt.Checkbox checkbox3;
        private java.awt.TextField textField1;
        // End of variables declaration
    }

    Two problems in the code you repost-ed:
    1. It lacks import statements.
    2. There is an extraneous } at the end of the button1ActionPerformed method.
    Correct them and it'll work fine. Posting the full source code:
    import java.awt.Component;
    import java.awt.Checkbox;
    public class Frame extends java.awt.Frame
         /** Creates new form Frame */
         public Frame()
              initComponents();
          * 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.
         private void initComponents()
              checkbox1 = new java.awt.Checkbox();
              checkbox2 = new java.awt.Checkbox();
              checkbox3 = new java.awt.Checkbox();
              button1 = new java.awt.Button();
              textField1 = new java.awt.TextField();
              setLayout( null );
              addWindowListener( new java.awt.event.WindowAdapter()
                   public void windowClosing( java.awt.event.WindowEvent evt )
                        exitForm( evt );
              checkbox1.setLabel( "checkbox1" );
              add( checkbox1 );
              checkbox1.setBounds( 120, 40, 84, 20 );
              checkbox2.setLabel( "checkbox2" );
              add( checkbox2 );
              checkbox2.setBounds( 120, 60, 84, 20 );
              checkbox3.setLabel( "checkbox3" );
              add( checkbox3 );
              checkbox3.setBounds( 120, 80, 84, 20 );
              button1.setLabel( "button1" );
              button1.addActionListener( new java.awt.event.ActionListener()
                   public void actionPerformed( java.awt.event.ActionEvent evt )
                        button1ActionPerformed( evt );
              add( button1 );
              button1.setBounds( 50, 170, 57, 24 );
              textField1.setText( "textField1" );
              add( textField1 );
              textField1.setBounds( 240, 170, 60, 20 );
              pack();
         private void button1ActionPerformed( java.awt.event.ActionEvent evt )
              // Add your handling code here:
              Component[] components = getComponents();
              int numOfCheckBoxes = 0;
              int numChecked = 0;
              for ( int i = 0; i < components.length; i++ )
                   if ( components[i] instanceof Checkbox )
                        numOfCheckBoxes++;
                        Checkbox checkBox = (Checkbox) components;
                        if ( checkBox.getState() )
                             numChecked++;
              double ratio = (double) numChecked / (double) numOfCheckBoxes;
              textField1.setText( Double.toString( ratio ) );
         /** Exit the Application */
         private void exitForm( java.awt.event.WindowEvent evt )
              System.exit( 0 );
         * @param args the command line arguments
         public static void main( String args[] )
              new Frame().show();
         // Variables declaration - do not modify
         private java.awt.Button button1;
         private java.awt.Checkbox checkbox1;
         private java.awt.Checkbox checkbox2;
         private java.awt.Checkbox checkbox3;
         private java.awt.TextField textField1;
         // End of variables declaration
    I can see from the code that the GUI was generated by a tool. Since you're new to Java programming, I'd recommend ditching the tool and writing everything by hand, otherwise you're not learning much. It's just like when you're learning proofs in Maths, where you start with first principles before making use of the proofs on their own.
    Also, it'll help tremendously if you could spend some time going through the Java Tutorial (http://java.sun.com/docs/books/tutorial/). It's free, and I find it very useful.
    Hth.

  • Help needed to trace a program ...

    Hi,
    I am trying to reach the program which actually generates the PO from ME21N/ME22N. Could you please help me trace or let me know the program name ??
    Once PO is created and if I have the print option set in the "Messages", the PO is printed to the printer. I want to trace after the point, the PO is saved in the table. i.e. from the time PO output is assembled for printing. also i want to know if its in .txt format ??
    thanks

    Hi Rad Sha,
    your program should be run in background, if you want to look that, you have to activate the background debuging.
    To do that, start a ME22N/ME21N, put /hs (in the field for the transaction). Save your PO, that will go in debuging. Use the button Setting, select the background debugging and press save.
    After this you could press the key F8.
    You will have a new window that will appear, in debug mode. This window correspond of the background.
    Rgd
    Frédéric

  • Help needed for java network programming

    How can I implement a GUI as a client in my server-client program.
    I have a window(JFrame)having one Textfield and a "Send" button.
    My requirement: While execution, the GUI should start as a client, and whatever textinput I will give to the Textfield, that should be printed in the server program.
    So, how can I implement a GUI window as a client.
    If any of U have idea,Please let me know soon.
    Regards.

    Well, the client part and the GUI part are separate. The button simply calls a send method.
    As for the networking, you can just use a Socket and a ServerSocket on the client and server, respectively. Then, wrap a PrintStream around one side and a BufferedReader(InputStreamReader()) around the other. You'll be able to talk back and forth once your connection is established; it's up to you to read from the BufferedReader and use the results on the server side.

  • Help needed new to Swing Programming

    Hi,
    I have Crated a JFrame (Frame1) with 4 textfields and a button (by name GetBarchart).
    My question is i will enter some values in 4 textfields and press the GetBarchart button it should display a new JFrame( say Frame2 ) and a Barchart with values taken form the 4 textfields should be displyed.
    NOTE: I should get the BarChart displayed in Frame2 , NOT in Frame1.
    anyhelp is appeciated .
    Thanks in advance

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.*;
    import org.jfree.data.category.*;
    import org.jfree.ui.*;
    // Make a main window with a top-level menu: File
    public class MainWindow extends JFrame {
        public MainWindow() {
            super("Menu System Test Window");
            setSize(500, 500);
            // make a top level File menu
            FileMenu fileMenu = new FileMenu(this);
            // make a menu bar for this frame
            // and add top level menus File and Menu
            JMenuBar mb = new JMenuBar();
            mb.add(fileMenu);
            setJMenuBar(mb);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    exit();
        public void exit() {
            setVisible(false); // hide the JFrame
            dispose(); // tell windowing system to free resources
            System.exit(0); // exit
        public static void main(String args[]) {
            MainWindow w = new MainWindow();
            w.setVisible(true);
        private static MainWindow w ;
        protected JTextField t1, t2, t3, t4;
        // Encapsulate the look and behavior of the File menu
        class FileMenu extends JMenu implements ActionListener {
            private MainWindow mw; // who owns us?
            private JMenuItem itmPE   = new JMenuItem("ProductEvaluation");
            private JMenuItem itmExit = new JMenuItem("Exit");
            public FileMenu(MainWindow main) {
                super("File");
                this.mw = main;
                this.itmPE.addActionListener(this);
                this.itmExit.addActionListener(this);
                this.add(this.itmPE);
                this.add(this.itmExit);
            // respond to the Exit menu choice
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == this.itmPE) {
                    JFrame f1 = new JFrame("ProductMeasurementEvaluationTool");
                    f1.setSize(1290,1290);
                    f1.setLayout(null);
                    t1 = new JTextField("0");
                    t1.setBounds(230, 630, 50, 24);
                    f1.add(t1);
                    t2 = new JTextField("0");
                    t2.setBounds(430, 630, 50, 24);
                    f1.add(t2);
                    t3 = new JTextField("0");
                    t3.setBounds(630, 630, 50, 24);
                    f1.add(t3);
                    t4 = new JTextField("0");
                    t4.setBounds(840, 630, 50, 24);
                    f1.add(t4);
                    JLabel l1 = new JLabel("Select the appropriate metrics for Measurement Process Evaluation");
                    l1.setBounds(380, 50, 380, 20);
                    f1.add(l1);
                    JLabel l2 = new JLabel("Architecture Metrics");
                    l2.setBounds(170, 100, 110, 20);
                    f1.add(l2);
                    JLabel l3 = new JLabel("RunTime Metrics");
                    l3.setBounds(500, 100, 110, 20);
                    f1.add(l3);
                    JLabel l4 = new JLabel("Documentation Metrics");
                    l4.setBounds(840, 100, 130, 20);
                    f1.add(l4);
                    JRadioButton rb1 = new JRadioButton("Componenent Metrics",false);
                    rb1.setBounds(190, 140, 133, 20);
                    f1.add(rb1);
                    JRadioButton rb2 = new JRadioButton("Task Metrics",false);
                    rb2.setBounds(540, 140, 95, 20);
                    f1.add(rb2);
                    JRadioButton rb3 = new JRadioButton("Manual Metrics",false);
                    rb3.setBounds(870, 140, 108, 20);
                    f1.add(rb3);
                    JRadioButton rb4 = new JRadioButton("Configuration Metrics",false);
                    rb4.setBounds(190, 270, 142, 20);
                    f1.add(rb4);
                    JRadioButton rb6 = new JRadioButton("DataHandling Metrics",false);
                    rb6.setBounds(540, 270, 142, 20);
                    f1.add(rb6);
                    JRadioButton rb8 = new JRadioButton("Development Metrics",false);
                    rb8.setBounds(870, 270, 141, 20);
                    f1.add(rb8);
                    JCheckBox  c10 = new JCheckBox("Size");
                    c10.setBounds(220, 170, 49, 20);
                    f1.add(c10);
                    JCheckBox c11 = new JCheckBox("Structure");
                    c11.setBounds(220, 190, 75, 20);
                    f1.add(c11);
                    JCheckBox c12 = new JCheckBox("Complexity");
                    c12.setBounds(220, 210, 86, 20);
                    f1.add(c12);
                    JCheckBox c13 = new JCheckBox("Size");
                    c13.setBounds(220, 300, 49, 20);
                    f1.add(c13);
                    JCheckBox c14 = new JCheckBox("Structure");
                    c14.setBounds(220, 320, 75, 20);
                    f1.add(c14);
                    JCheckBox c15 = new JCheckBox("Complexity");
                    c15.setBounds(220, 340, 86, 20);
                    f1.add(c15);
                    JCheckBox c19 = new JCheckBox("Size");
                    c19.setBounds(580, 170, 49, 20);
                    f1.add(c19);
                    JCheckBox c20 = new JCheckBox("Structure");
                    c20.setBounds(580, 190, 75, 20);
                    f1.add(c20);
                    JCheckBox c21 = new JCheckBox("Complexity");
                    c21.setBounds(580, 210, 86, 20);
                    f1.add(c21);
                    JCheckBox c22 = new JCheckBox("Size");
                    c22.setBounds(580, 300, 49, 20);
                    f1.add(c22);
                    JCheckBox c23 = new JCheckBox("Structure");
                    c23.setBounds(580, 320, 75, 20);
                    f1.add(c23);
                    JCheckBox c24 = new JCheckBox("Complexity");
                    c24.setBounds(580, 340, 86, 20);
                    f1.add(c24);
                    JCheckBox c28 = new JCheckBox("Size");
                    c28.setBounds(920, 170, 49, 20);
                    f1.add(c28);
                    JCheckBox c29 = new JCheckBox("Structure");
                    c29.setBounds(920, 190, 75, 20);
                    f1.add(c29);
                    JCheckBox c30 = new JCheckBox("Complexity");
                    c30.setBounds(920, 210, 86, 20);
                    f1.add(c30);
                    JCheckBox c31 = new JCheckBox("Size");
                    c31.setBounds(920, 300, 49, 20);
                    f1.add(c31);
                    JCheckBox c32 = new JCheckBox("Structure");
                    c32.setBounds(920, 320, 75, 20);
                    f1.add(c32);
                    JCheckBox c33 = new JCheckBox("Complexity");
                    c33.setBounds(920, 340, 86, 20);
                    f1.add(c33);
                    ActionListener action = new MyActionListener(f1, t1, t2,t3,t4);
                    JButton b1  = new JButton("Button1");
                    b1.setBounds(230, 600, 120, 24);
                    b1.addActionListener(action);
                    f1.add(b1);
                    JButton b2  = new JButton("Button2");
                    b2.setBounds(430, 600, 120, 24);
                    b2.addActionListener(action);
                    f1.add(b2);
                    JButton b3  = new JButton("Button3");
                    b3.setBounds(630, 600, 120, 24);
                    b3.addActionListener(action);
                    f1.add(b3);
                    JButton b4  = new JButton("Button4");
                    b4.setBounds(840, 600, 120, 24);
                    b4.addActionListener(action);
                    f1.add(b4);
                    JButton b5  = new JButton("Generatechart");
                    b5.setBounds(1040, 600, 120, 24);
                    b5.setBounds(530, 660, 120, 24);//uhrand
                    b5.addActionListener(action);
                    f1.add(b5);
                    f1.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            System.exit(0);
                    f1.setVisible(true);
                } else {
                    mw.exit();}
        class MyActionListener implements ActionListener {
            private JFrame     f1;
            private JTextField t1;
            private JTextField t2;
            private JTextField t3;
            private JTextField t4;
            private  final DecimalFormat result = new DecimalFormat("0.0");
            public MyActionListener(JFrame f1, JTextField tf1, JTextField tf2,JTextField tf3,JTextField tf4) {
                this.f1 = f1;
                this.t1 = tf1;
                this.t2 = tf2;
                this.t3 = tf3;
                this.t4 = tf4;
            public void actionPerformed(ActionEvent e) {
                String s = e.getActionCommand();
                if (s.equals("Button1")) {
                    Component[] components = this.f1.getContentPane().getComponents();
                    int numOfCheckBoxes = 81;
                    int numChecked = 0;
                    for (int i = 0; i < components.length; i++)
                        if (components[i] instanceof JCheckBox)
                            if (((JCheckBox)components).isSelected())
    numChecked++;
    double ratio = ((double) numChecked / (double) numOfCheckBoxes)*100;
    this.t1.setText(result.format(ratio) );
    }else if (s.equals("Button2")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+5);
    this.t2.setText(result.format(ratio) );
    }else if (s.equals("Button3")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+10);
    this.t3.setText(result.format(ratio) );
    }else if (s.equals("Button4")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+15);
    this.t4.setText(result.format(ratio) );
    }else if (s.equals("Generatechart")) {
    Bar_Chart barChart = new Bar_Chart("Bar Chart", t1.getText(),t2.getText(),t3.getText(),t4.getText());
    barChart.pack();
    RefineryUtilities.centerFrameOnScreen(barChart);
    barChart.setVisible(true);
    class Bar_Chart extends JDialog {
    String t1,t2,t3,t4;
    public Bar_Chart(String title, String t1, String t2, String t3, String t4) {
    this.t1=t1;
    this.t2=t2;
    this.t3=t3;
    this.t4=t4;
    setModal(true);
    setTitle(title);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    CategoryDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartPanel);
    private CategoryDataset createDataset() {
    String series1 = "First";
    String series2 = "Second";
    String series3 = "Third";
    String series4 = "Fourth";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(Double.parseDouble(t1.replace(',','.')), series1, "");
    dataset.addValue(Double.parseDouble(t2.replace(',','.')), series2, "");
    dataset.addValue(Double.parseDouble(t3.replace(',','.')), series3, "");
    dataset.addValue(Double.parseDouble(t4.replace(',','.')), series4, "");
    return dataset;
    private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
    "Bar Chart", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.VERTICAL, // orientation
    true, // include legend
    true, // tooltips?
    false // URLs?
    return chart;

Maybe you are looking for

  • DV6000 wont start (No LED lights or anything)

    1. HP Pavilion DV6000 2. Windows XP 2005 3. Unable to get that far, so no error I know of. 4. No changes recently Hello, I have been given a DV6000 from a friend to fix and he didn't have a charger so I bought a new one. The one I purchased is a DC35

  • May i know how can i include a search filter box in Muse?

    Hi, i'm going to set up a website which contain a lot of list and I would like to include a search filter box where user get to filter their search result in the list that I inserted. Is there any good tutorials or pre-post that i can refer? Thank yo

  • Using an external reference clock for counter measuremen​ts

    Hi all, I have several PXI chassis configured for testing, each of which uses an NI-DAQ-6221 for conducting period and frequency measurements among other things. However each of my setups give me a slightly different reading when conducting identical

  • Archive log files are not being created

    I am doing some testing of the backup and recovery of our databases. I have a database which is in archive log mode. I have added some records to a table and I am expecting to see some archive files being written to but nothing is being produced. We

  • How to integrate DWR and JAVA Webservice?

    This is S.korea! so sorry for my poor English :-P I'm developing java Web service and my client is Ajax system.My toolkit for Ajax is DWR. But I don't know how to integrated DWR and Java Web service! Function invocation in web service is synchronous.