Colour Chooser Urgent Querie

Hello,
Please help! I need to design a “Colour Chooser” using TWO classes and I need a little help with it.
Basically, there are three panels on a frame containing:
1. A Canvas (Panel 1)
2. Three JScrollbars (Panel 2 - relating to Red Green and Blue )
3. Three JTextfields (Panel 3 - relating to Red Green and Blue)
You can either move the scrollbars OR enter RGB values into the textfields and the Canvas will change colour accordingly to the RGB values entered.
My problem is not that difficult, but just that in the first class (public class ColourChooser)I have to:
 Create a constructor that will add the scrollbars, textfields and canvas to the frame
 Add the actionlisteners and required methods for actionlisteners also.
(I have this done - it's the next class giving me grief!)
In the second class (public class DrawCanvas) I have to:
 Declare variables to represent the colours Red Green and Blue
 Create a constructor that will set the size of the canvas????
 Create a method called paint that sets the colour of the rectangle and fills it in.
 Create a method called setCanvasColour that will accept the variables representing the three colours and repaint the canvas.
My Query:
If the canvas is declared in the first class, how can I set it’s size in another class?
I can't use inheritance as the first class inherits from JFrame and only one class can be inherited per sub-class.
I have gotten some replies on this but still not sure, I am able to add and set the size of the canvas in the first class, but the exercise is to set the size of the canvas from the second class.
I know that JColorChooser is a handier option but am not allowed to use it. I could really do with some code snippets here guys.
Please help me I’m really stumped.

Annoyingly cross-posted: http://forum.java.sun.com/thread.jspa?threadID=581154&messageID=2948475

Similar Messages

  • Colour Chooser GUI - Urgent Querie!!

    Hello,
    Please help! I need to design a �Colour Chooser� using TWO classes(ColourChooser and DrawCanvas) and I need a little help with it.
    Basically, there are three panels on a frame.
    1.     A Canvas
    2.     Three JScrollbars (relating to Red Green and Blue )
    3.     Three JTextfields (relating to Red Green and Blue)
    You can either move the scrollbars OR enter RGB values into the textfields and the Canvas will change colour accordingly.
    My problem is not that difficult, but just that in the first class I have to:
    �     Create a constructor that will add the scrollbars, textfields and canvas to the frame
    �     Add the actionlisteners and required methods for actionlisteners also.
    In the second class I have to:
    �     Declare variables to represent the colours Red Green and Blue
    �     Create a constructor that will set the size of the canvas
    �     Create a method called paint that sets the colour of the rectangle and fills it in.
    �     Create a method called setCanvasColour that will accept the variables representing the three colours and repaint the canvas.
    My Query:
    How do I make these classes interact with each other. I can�t use inheritance as the first class will �extend JFrame� and each class can only extend one super class.
    If the canvas is declared in the first class, how can I set it�s size in another class?
    Please help me I�m really stumped.
    Your friend in Java.
    Stoney

    Hello,
    Please help! I need to design a “Colour Chooser” using TWO classes and I need a little help with it.
    Basically, there are three panels on a frame containing:
    1. A Canvas
    2. Three JScrollbars (relating to Red Green and Blue )
    3. Three JTextfields (relating to Red Green and Blue)
    You can either move the scrollbars OR enter RGB values into the textfields and the Canvas will change colour accordingly.
    My problem is not that difficult, but just that in the first class (public class ColourChooser)I have to:
     Create a constructor that will add the scrollbars, textfields and canvas to the frame
     Add the actionlisteners and required methods for actionlisteners also.
    In the second class (public class DrawCanvas) I have to:
     Declare variables to represent the colours Red Green and Blue
     Create a constructor that will set the size of the canvas????
     Create a method called paint that sets the colour of the rectangle and fills it in.
     Create a method called setCanvasColour that will accept the variables representing the three colours and repaint the canvas.
    My Query:
    If the canvas is declared in the first class, how can I set it’s size in another class?
    I have gotten some replies on this but still not sure, I am able to add and set the size of the canvas in the first class, but the exercise is to set the size of the canvas from the second class.
    I know that JColorChooser is a handier option but am not allowed to use it. I could really do with some code snippets here guys.
    Please help me I’m really stumped.

  • AWT colour chooser and paint

    Hi, this is quite simple but I don't know how to do it, please help!
    The following code should do the following: click in a colour, and paint with the chosen colour .. I cannot make it paint with the colour I choose :(
    import java.awt.*;
    import java.awt.event.*;
    public class E3Events
         extends Frame
         implements MouseListener, MouseMotionListener
         Color colorActual;
         public static void main(String[] args)
              E3Events e3 = new E3Events();
              e3.setTitle("Paint");
              e3.setSize(500, 500);
              e3.addMouseListener(e3);
              e3.addMouseMotionListener(e3);
              e3.show();
         public void paint(Graphics g)
              g.setColor(Color.GREEN);
              g.fillRect(0, 0, 100, 100);
              g.setColor(Color.YELLOW);
              g.fillRect(100, 0, 100, 100);
              g.setColor(Color.RED);
              g.fillRect(200, 0, 100, 100);
              g.setColor(Color.ORANGE);
              g.fillRect(300, 0, 100, 100);
              g.setColor(Color.BLUE);
              g.fillRect(400, 0, 100, 100);
         public void mouseDragged(MouseEvent e)
              Graphics g = getGraphics();
              g.setColor(colorActual);
              int x = e.getX();
              int y = e.getY();
              g.fillOval(x, y, 10, 10);
         public void mouseClicked(MouseEvent e)
         * @see java.awt.event.MouseListener#mouseEntered(MouseEvent)
         public void mouseEntered(MouseEvent arg0)
         * @see java.awt.event.MouseListener#mouseExited(MouseEvent)
         public void mouseExited(MouseEvent arg0)
         * @see java.awt.event.MouseListener#mousePressed(MouseEvent)
         public void mousePressed(MouseEvent arg0)
         * @see java.awt.event.MouseListener#mouseReleased(MouseEvent)
         public void mouseReleased(MouseEvent arg0)
         * @see java.awt.event.MouseMotionListener#mouseMoved(MouseEvent)
         public void mouseMoved(MouseEvent arg0)
    Thanks a million in advance

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import java.util.List;
    public class ColorPainting
        public static void main(String[] args)
            ColorPaintPanel cpPanel = new ColorPaintPanel();
            Frame f = new Frame();
            f.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
            f.add(cpPanel.getColorPanel(), "North");
            f.add(cpPanel);
            f.setSize(400,300);
            f.setLocation(200,200);
            f.setVisible(true);
    class ColorPaintPanel extends Panel
        Color color;
        Point lastPoint;
        List liveList, lineList;
        public ColorPaintPanel()
            liveList = new ArrayList();
            lineList = new ArrayList();
            addMouseListener(new Starter());
            addMouseMotionListener(new Generator());
        public void paint(Graphics g)
            super.paint(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(color);
            Shape s;
            for(int i = 0; i < liveList.size(); i++)
                s = (Shape)liveList.get(i);
                g2.draw(s);
            for(int i = 0; i < lineList.size(); i++)
                s = (Shape)lineList.get(i);
                g2.draw(s);
        public void update(Graphics g)
            paint(g);
        private class Starter extends MouseAdapter
            public void mousePressed(MouseEvent e)
                lastPoint = e.getPoint();
            public void mouseReleased(MouseEvent e)
                lineList.addAll(liveList);
                liveList.clear();
        private class Generator extends MouseMotionAdapter
            public void mouseDragged(MouseEvent e)
                Point currentPoint = e.getPoint();
                Shape s = new Line2D.Float(lastPoint, currentPoint);
                liveList.add(s);
                lastPoint = currentPoint;
                repaint();
        public Panel getColorPanel()
            final Button
                greenButton = new Button("green"),
                yellowButton = new Button("yellow"),
                redButton = new Button("red"),
                orangeButton = new Button("orange"),
                blueButton = new Button("blue");
            ActionListener l = new ActionListener()
                public void actionPerformed(ActionEvent e)
                    Button button = (Button)e.getSource();
                    if(button == greenButton)
                        color = Color.green;
                    if(button ==yellowButton)
                        color = Color.yellow;
                    if(button == redButton)
                        color = Color.red;
                    if(button == orangeButton)
                        color = Color.orange;
                    if(button == blueButton)
                        color = Color.blue;
            greenButton.addActionListener(l);
            yellowButton.addActionListener(l);
            redButton.addActionListener(l);
            orangeButton.addActionListener(l);
            blueButton.addActionListener(l);
            Panel panel = new Panel();
            panel.add(greenButton);
            panel.add(yellowButton);
            panel.add(redButton);
            panel.add(orangeButton);
            panel.add(blueButton);
            return panel;
    }

  • How do i get my printer to print in colour? urgent:(

    Hey guys,
    I have recently bought a samsung CLX-3180 series and i sought for the updates and found them, now it copies in colour when i select that option but whenever i print via the mac it only prints in black, whatever i do. How do i solve this?

    select print, or command p. when the print window comes up, select the printer you wish to use, then select the preset in the drop down window, black and white draft best color, etc.

  • Excel Charts do not get displayed correctly (colour) !urgent!

    Hi,
    believe me: I spent days in research to fix my problem but could not find a solution yet...
    I use a lot of Excel Web Parts on my SharePoint Site. Basically to display charts or tables. Everything worked fine for months but out of a sudden some of the web parts do not anymore. These Web Parts still get displayed but all in black or grey and
    because of that are partly unreadable. For example: a cell with a white font and a blue blackground just gets displayed as a black cell with black fontcolour. I thought it might depends on the settings of the server computer but other colourful charts/tables
    still work fine (but on the other hand, all new web parts do not get displayed correctly...)
    I tried to remove macros, conditional formatting, creating completely new subsites with content. But the result is always the same: black cells.
    Then I tried to just use 8bit-colours and tada: it worked (except of the colour white, that still does not work).. I do not have access to the server computer. And I am wondering because some other charts still work..
    Any ideas?
    I do not use SharePoint Designer, just the browser version of 2010.
    Thanks for your help!!!

    Here is the code:
    IANode QueryContractResultNode = wdContext.nodeA();
    IBNode ToolTipNode = wdContext.nodeToolTipNode();
    QueryContractResultNode.invalidate();
    for(int i=0; i<searchContractListSize; i++)
       IAElement newQueryContractResultEl =   QueryContractResultNode.createAElement();
    WDCopyService.copyCorresponding(getList.getOutput().getI_Detail().get(i),newQueryContractResultEl);
    IBElement newToolTipEl = ToolTipNode.createBElement();
    if(newQueryContractResultEl.getParentName().length() >= 5)
         newToolTipEl.setChildName  (newQueryContractResultEl.getParentName().substring(0,4) + "...");
    else
         newToolTipEl.setChildName (newQueryContractResultEl.getParentName());
    QueryContractResultNode.addElement(newQueryContractResultEl);
    ToolTipNode.addElement(newToolTipEl);
    Node A is bound to a model structure.  Therefore, the value of A.parentName is set after the RFC execution.
    Zita

  • Macbook Pro Colour issues - urgent

    Hi,
    The colours of my screen change and i would like to know what is the problem and how can we fix it. The holo MB crashed and I need to restart it to solved this problem for some hours or days. This is my screen when colours change.

    as i see this might be a Graphics card error but in any case i have seen other possibilities aswell such as a loosy connection between your display and graphics card that happens in time, if your mabook pro is old and as i see in the picture it shouldn't be that old to have this problem. anyways from my own experience, exactly what happened to me by old mabook late 2008 started the same symptoms then i couldn't even restart or control the system i had to push and hold the power button, after restarting everything was fine again for a period of time then the same thing happened over and over again so what i did i tried a disk verification and i found out that my disk nodes were courpt so i had to format the drive and start all over again. i suggest try to get a backup first before doing anything then try a permission verification and repair then a disk verification and repair

  • HFR Urgent Queris :  Small thing...but not working...........

    Hi All,
    I'm facing small prob. but i became big one.
    Prob. 1) : in column A i have year dim with prompt.
    in column b i need previous year of col A.
    For this , in col b i used relative function with same as col a - 1.
    but its not working.
    Prob 2) : I have 2 grids. in col a,b i pull the data from same grid and col c,d i need to create a formula var of grid2
    col a,b.
    For this, i used the formula like this var(grid1.col[a],grid2.col[a]).but when i run the report it shows #error. Any idea.
    Plz give me any solution for these probs......
    Thanks

    For Prob 1: Instead of using prompt for year, you can use POV selection for year, so remove the prompt, and make it current user POV for year for column A. For column B make it Relative member of Current POV for year with offset -1.
    or you can put prompts on both column A and column B,, so the user will have to select two years manually, and this gives the user the chance of using any year he wants for column B instead of using always selected year -1.
    For Prob 2: Since you want to calculate var of the 2 columns of 2 different grids, I am assuming that the rows of the both grids are exactly same. So, If you can add another column to Grid1 and make it same with column A of grid 2, then use it with your calculation. If you want you can hide it.
    hope this helps
    Bulent

  • BI Content Queries

    Hey Guys,
    How do I install BI Content Queries and then how do I access them?
    Thanks!

    Hi Dezi,
    You install them from RSA1 > Business Content > Here you can choose the queries that you want to install. Then you can view them in the Bex Query designer and run them in the Analyzer (if the InfoProvider on which they are based has some data).
    http://help.sap.com/saphelp_nw04/helpdata/en/80/1a66d5e07211d2acb80000e829fbfe/content.htm
    Hope this helps...

  • Colours different on object and inspector

    Hi,
    For most colours, there seems to be a subtle difference in the appearance of the fill colour of an object, and the colour for the object shown in the inspector/colour chooser. The object shown on the page has more saturation or brightness than in the floating palettes.
    This is immediately noticeable to me on the default green colour for a new object from the toolbar menu (eg. a new circle). In fact, if I click the magnifying glass on the colour palette and click my object, even though they're meant to be the same colour, both the inspector and object change colour slightly, proving that it's not just my eyes. I can repeat this again and again on the object of default green fill until the object is bright green (green starts on 183 of RGB and ends up on 255.)
    The problem is the same with text and lines in Pages, but this does not happen in TextEdit. Text copied directly from TextEdit into Pages has a slightly different color.
    Does anyone else experience this? Any fixes?
    Thanks

    This was brought up in the Keynote forum quite some time ago, compllete with a handy demonstration by Kyn.
    I would suggest sending feedback and seeing if it shows up in keynote too. If it doesn't then it was a missed fix in color handling that was not forwarded to the Pages team.

  • HELP - Urgent Query - utf-8

    I have just started using the Oracle 11g database - with no exprience :(
    Unfortunatly i need some information. I have exprience with SQL but none with oracle Databases
    I need to urgently change a database format to UTF-8 however i can find NO option to do this despite the documentation stating you select this when creating a database.
    im using the http://XXXX/em - enterprise manager 11g
    Please can someone give me a top level overview on where i can accomplish this.
    I have read through numerous articles but none that EXPLAIN how to do this.
    the database has no information - and newly created ones dont have an option to change this.
    please help

    In a forum of volunteers there are no urgent queries.
    Your use of the word 'urgent' is disrespectful and rude.
    As UTF-8 is a multi-byte characterset, and multibyte charactersets are not supersets of single-byte charactersets, you need to create a new database in the correct characterset.
    If you want to retain the name, you can use dbca (Database Creation Assistant) to delete the current database first.
    Sybrand Bakker
    Senior Oracle DBA

  • How to delete copyed wrongly in the data base

    Hi Gurus,
    I  copy the cube 0IC_C03 to Z0IC_C03.
    After that i went to RSZC--> copy from 0IC_C03 to Z0IC_C03 all the queries, but when i am copying i dint remove the _1 beside each query. when i repeat system telling queries already in the data base. can you tell how to delete and copy freshly.
    Points Assure.
    Thanks
    Amarendra

    Hi,
    you can use rszdelete where you can choose the queries and query objects which you want to delete.
    After this you can start the copy again.
    regards
    Cornelia

  • Can I change the Default Position of a JColorChooser Dialog Box???

    I am working on a drawing application where I am using a button that launches a JColorChooser dialog to allow a user to select a color which. I have tied this button to the JColorChooser using the source code below to reset the color based on the user's selection. This all works fine. However, when the JColorChooser comes up, the dialog comes up right in the middle of the drawing area and erases any portion of the drawing that the dialog box overlaps with, which having my luck is more or less right in the middle of the JPanel where I am doing the drawing. My question is can I tell the JColorChooser to come up somewhere else in the user interface by offsetting it from the actual application somehow? I am using a JFrame to add all of these components to (the color choose button and the drawing area) and wonder if there is a way to tell the JColorChooser dialog not to come in the default location. Any help that anybody could provide would be greatly appreciated. Thanks!
    Kevin
    pickColor = new JButton( "Choose Color" );
    pickColor.addActionListener(
    new ActionListener() {
    public void actionPerformed(ActionEvent event)
    color = JColorChooser.showDialog(
    ColorPicker.this, "Choose a color", color);
    if ( color == null )
    currentColor = Color.RED;
    else
    currentColor = color;
    );

    JColorChooser has a method createDialog() that lets you create (rather than
    merely show) a dialog containing your colour chooser.
    If you use this method you can position the dialog wherever you want. The
    dialog inherits the Window methods for positioning - eg
    setLocationRelativeTo(Component c).

  • Can I change the way iCal displays events in Month view?

    I don't like the way iCal in the new OS displays events in Month view.  It's counter intuitive to have the time of the event be at the far right and grayed out.  I find myself staring and slowly scanning down the display just to find out when I have to be at an appointment.  I wish they had stayed with the other display, not only was it much clearer, it also word wrapped so you could see the entire description.  I have blank space at the bottom of the day, and at the same time missing information because of the lack of wrapped text.

    Hi Daniel,
    The option you have there is to change the calendar of the event (currently the "University" calendar in your screen shot) not the colour.  It is the calendars that have colours in iCal not the events.
    To change the calendar colour in OSX 10.7:
    Click Calendars (in the top-left corner of the iCal window), and select the calendar by clicking its name in the Calendars pop-up list.
    Choose Edit > Get Info.
    Choose a new colour from the pop-up menu in the top-right corner of the Info window.
    To customize the colour, choose Other, and then make your colour selections in the Colours window.
    I hope that helps.
    Best wishes
    John M

  • Networking - Why Doesn't This Work?

    Hey all
    Just wondering if any of you have any ideas why this code isn't working properly - for the Client to connect the Server has to be restarted. Is there a solution to this problem?
    The Client Class:
    import java.awt.Container;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.FlowLayout;
    import java.awt.Dimension;
    import java.awt.GridBagLayout;
    import java.awt.GridBagConstraints;
    import java.awt.Insets;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JColorChooser;
    import javax.swing.ButtonGroup;
    import javax.swing.Box;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.BoxLayout;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JLabel;
    import javax.swing.JComboBox;
    import javax.swing.JOptionPane;
    import javax.swing.JRadioButton;
    import java.io.*;
    import java.net.*;
    * This is the user class and holds all the details for the GUI. The gui contains listeners
    * ans it sends messages to the server and also recieves messages from the server. This class
    * works primarily with the ClienttoServer class.
    * Help was used to create this class, mainly from the Java GUI devlopment book by Varan Piroumian
    * as this hsowed the basic components needed to create a GUI and which imports were the most essential
    * in order to have an interactive interface for the chat application.
    public class Client extends JFrame implements ActionListener
         private static final long serialVersionUID = 1L;
         private JTextArea conversationDisplay;
         private JTextField createMsg, hostfield, portnumfd, usernamey;
         private JScrollPane scrolly;
         private JLabel hosty, portnum, convoLabel, msgLabel, netwrk, netwrk2, talk2urself, fonts, nickName, ustatus, econs;
         private JPanel lpanel, rpanel, lpanel1, lpanel2, lpanel3, lpanel4, lpanel5, rpanel1, rpanel2, rpanel3, rpanel4, rpanel5;
         private JButton sendMsgButton, colourButton, exitButton, connect, dropconnection;
         private JRadioButton talk2urselfOn, talk2urselfOff;
         private JComboBox fontcombiBox, statusbox, emoticons;
         private JColorChooser colourchoo;
         private Container theWholeApp;
         private String username;
         private PrintWriter writer;
         private Socket socky;
         //for the self comm button
         private boolean talktoself = true;
         //used as when a msg is sent to the server the name & msg are sent in 2 parts (\n function) i.e
         //2 different messages. So in self comm mode then the next message needs to be ignored
         private boolean ignoreyourself = false;
          * The Constructor or the class
         public Client()
              makeGUI();
              System.out.println("Loading the GUI....");
          * Creates the GUI for the user to see/use
         public void makeGUI()
              //create the whole window
              JFrame.setDefaultLookAndFeelDecorated(true);
              //set the title of the whole app
              this.setTitle("Welcome To Elliot's Chat Network...");
              //set the app window size
              this.setSize(600, 575);
              //create the outer container for the app
              theWholeApp = getContentPane();
              //make new gridbag layout
              GridBagLayout layoutgridbag = new GridBagLayout();
              //create some restraints for this...
              GridBagConstraints gbconstraints = new GridBagConstraints();
              //make the app use this gridbag layout
              theWholeApp.setLayout(layoutgridbag);
              //this is where elements are added into the application's window
              //creates and adds the convo label
              convoLabel = new JLabel("Your Conversation:");
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 0;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 5;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.WEST;
              layoutgridbag.setConstraints(convoLabel, gbconstraints);
              theWholeApp.add(convoLabel);
              //create & add the exit button
              exitButton = new JButton("Exit");
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 10;
              gbconstraints.gridy = 0;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 1;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.EAST;
              layoutgridbag.setConstraints(exitButton, gbconstraints);
              theWholeApp.add(exitButton);
              exitButton.addActionListener(this);
              //create & add the txt area
              conversationDisplay = new JTextArea(15,15);
              scrolly = new JScrollPane(conversationDisplay);
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 1;
              gbconstraints.gridheight = 4;
              gbconstraints.gridwidth = 11;
              gbconstraints.weightx = 10;
              gbconstraints.weighty = 20;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.fill = GridBagConstraints.BOTH;
              gbconstraints.insets = new Insets(10, 10, 15, 15);
              //so the clients cant write in the display area...
              conversationDisplay.setEditable(false);
              layoutgridbag.setConstraints(scrolly, gbconstraints);
              theWholeApp.add(scrolly);
              //create & add the nick name area
              nickName = new JLabel("Your nick \nthis is required");
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 5;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 5;
              gbconstraints.weighty = 1.5;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.fill = GridBagConstraints.HORIZONTAL;
              gbconstraints.insets = new Insets(3, 10, 0, 0);
              layoutgridbag.setConstraints(nickName, gbconstraints);
              theWholeApp.add(nickName);
              //create & add the nick name box
              usernamey = new JTextField(10);
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 6;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 1;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.fill = GridBagConstraints.HORIZONTAL;
              gbconstraints.insets = new Insets(0, 10, 0, 0);
              layoutgridbag.setConstraints(usernamey, gbconstraints);
              theWholeApp.add(usernamey);
              //create & add the your message label
              msgLabel = new JLabel("Your Message:");
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 7;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 1;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.fill = GridBagConstraints.BOTH;
              gbconstraints.insets = new Insets(0, 10, 0, 0);
              layoutgridbag.setConstraints(msgLabel, gbconstraints);
              theWholeApp.add(msgLabel);
              //create & add the create message box
              createMsg = new JTextField(15);
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 8;
              gbconstraints.gridheight = 2;
              gbconstraints.gridwidth = 10;
              gbconstraints.weightx = 10;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.fill = GridBagConstraints.HORIZONTAL;
              gbconstraints.insets = new Insets(3, 10, 0, 0);
              layoutgridbag.setConstraints(createMsg, gbconstraints);
              theWholeApp.add(createMsg);
              createMsg.addActionListener(this);
              createMsg.setActionCommand("Press Enter!");
              //create & add the send message button
              sendMsgButton = new JButton("Send Msg");
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 10;
              gbconstraints.gridy = 8;
              gbconstraints.gridheight = 1;
              gbconstraints.gridwidth = 1;
              gbconstraints.weightx = 1;
              gbconstraints.weighty = 1;
              gbconstraints.anchor = GridBagConstraints.EAST;
              layoutgridbag.setConstraints(sendMsgButton, gbconstraints);
              theWholeApp.add(sendMsgButton);
              sendMsgButton.addActionListener(this);
              //create & add the left panel
              lpanel = new JPanel();
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 0;
              gbconstraints.gridy = 10;
              gbconstraints.gridheight = 3;
              gbconstraints.gridwidth = 4;
              gbconstraints.weightx = 5;
              gbconstraints.weighty = 0;
              gbconstraints.anchor = GridBagConstraints.WEST;
              gbconstraints.insets = new Insets(0, 10, 0, 0);
              layoutgridbag.setConstraints(lpanel, gbconstraints);
              theWholeApp.add(lpanel);
              //create & add the right panel
              rpanel = new JPanel();
              gbconstraints = new GridBagConstraints();
              gbconstraints.gridx = 5;
              gbconstraints.gridy = 10;
              gbconstraints.gridheight = 3;
              gbconstraints.gridwidth = 4;
              gbconstraints.weightx = 5;
              gbconstraints.weighty = 0;
              gbconstraints.anchor = GridBagConstraints.EAST;
              layoutgridbag.setConstraints(rpanel, gbconstraints);
              theWholeApp.add(rpanel);
              //add to the left JPanel - set the layout for this
              lpanel.setLayout(new BoxLayout(lpanel, BoxLayout.Y_AXIS));
              //add panels into this left panel...
              lpanel1 = new JPanel();
              lpanel2 = new JPanel();
              lpanel3 = new JPanel();
              lpanel4 = new JPanel();
              lpanel5 = new JPanel();
              lpanel.add(lpanel1);
              lpanel.add(lpanel2);
              lpanel.add(lpanel3);
              lpanel.add(lpanel4);
              lpanel.add(lpanel5);
              //set FlowLyout for each of these panels
              lpanel1.setLayout(new FlowLayout(FlowLayout.LEFT));
              lpanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
              lpanel3.setLayout(new FlowLayout(FlowLayout.LEFT));
              lpanel4.setLayout(new FlowLayout(FlowLayout.LEFT));
              lpanel5.setLayout(new FlowLayout(FlowLayout.LEFT));
              //add in the network items...
              netwrk = new JLabel("Network Details:");
              lpanel1.add(netwrk);
              //create and add instructions for this
              netwrk2 = new JLabel("Please enter the details for \nthe person you want to chat to...");
              lpanel2.add(netwrk2);
              //create/add the ip addy label
              hosty = new JLabel("Host:");
              lpanel3.add(hosty);
              lpanel3.add(Box.createRigidArea(new Dimension(5,0)));
              hostfield = new JTextField("Enter Hostname",10);
              lpanel3.add(hostfield);
              //port num next
              portnum = new JLabel("Port Number:");
              lpanel4.add(portnum);
              lpanel4.add(Box.createRigidArea(new Dimension(5, 0)));
              portnumfd = new JTextField("2250", 10);
              lpanel4.add(portnumfd);
              //create & add the connect butt
              connect = new JButton("Connect");
              lpanel5.add(connect);
              dropconnection = new JButton("Disconnect");
              lpanel5.add(dropconnection);
              connect.addActionListener(this);
              dropconnection.addActionListener(this);
              //start the creation of the right hand panel.
              rpanel.setLayout(new BoxLayout(rpanel, BoxLayout.Y_AXIS));
              //create the panels again
              rpanel1 = new JPanel();
              rpanel2 = new JPanel();
              rpanel3 = new JPanel();
              rpanel4 = new JPanel();
              rpanel5 = new JPanel();
              rpanel.add(rpanel1);
              rpanel.add(rpanel2);
              rpanel.add(rpanel3);
              rpanel.add(rpanel4);
              rpanel.add(rpanel5);
              rpanel1.setLayout(new FlowLayout(FlowLayout.LEFT));
              rpanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
              rpanel3.setLayout(new FlowLayout(FlowLayout.LEFT));
              rpanel4.setLayout(new FlowLayout(FlowLayout.LEFT));
              rpanel5.setLayout(new FlowLayout(FlowLayout.LEFT));
         //now start putting things into them again
              //add in the font settings
              String[] fonty = {"Normal", "Bold", "Italic"};
              fonts = new JLabel("Set your text style:");
              fontcombiBox = new JComboBox(fonty);
              rpanel2.add(fonts);
              rpanel2.add(Box.createRigidArea(new Dimension(4,0)));
              rpanel2.add(fontcombiBox);
              //default text will be plain..
              fontcombiBox.setSelectedIndex(0);
              String[] userstatus = {"Online", "Away", "Be Right Back", "Busy", "Out To Lunch", "On The Phone"};
              ustatus = new JLabel("Select a status:");
              statusbox = new JComboBox(userstatus);
              rpanel2.add(ustatus);
              rpanel2.add(Box.createRigidArea(new Dimension(2,0)));
              rpanel2.add(statusbox);
              //add in some emotion to the conversations
              String[] emotion = {"Angry", "Happy", "Sad", "Crying", "Shocked", "Laughing", "Laughing My Ass Off!"};
              econs = new JLabel("Select an emoticon:");
              emoticons = new JComboBox(emotion);
              rpanel3.add(econs);
              rpanel3.add(Box.createRigidArea(new Dimension(3,0)));
              rpanel3.add(emoticons);
              //self comm options
              talk2urself = new JLabel("Set Self Communication Mode:");
              rpanel4.add(talk2urself);
              talk2urselfOn = new JRadioButton("On", true);
              rpanel4.add(talk2urselfOn);
              rpanel4.add(Box.createRigidArea(new Dimension(4, 0)));
              talk2urselfOff = new JRadioButton("Off", false);
              rpanel4.add(talk2urselfOff);
              //create a group that will hold both these buttons together
              ButtonGroup groupy = new ButtonGroup();
              //add them to the group
              groupy.add(talk2urselfOn);
              groupy.add(talk2urselfOff);
              //create and add the change backgrd button
              colourButton = new JButton("Alter Background");
              rpanel5.add(colourButton);
              //add in some listeners
              talk2urselfOn.addActionListener(this);
              talk2urselfOff.addActionListener(this);
              fontcombiBox.addActionListener(this);
              colourButton.addActionListener(this);
              statusbox.addActionListener(this);
              //add in the 'X' button in the top right corner of app
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //put all elements together
              this.pack();
              //show the GUI for the user..
              this.show();
          * Creates a new client and GUI as its the main method
         public static void main(String args[])
              new Client();
          * This method listens for actions selected by the user and then performs the
          * necessary tasks in order for the correct events to take place...!
          * This method was mainly created thanks to the Developing Java GUI book which has already
          * been mentioned as it covers listeners and event handling...
         public void actionPerformed(ActionEvent event)
              //if the send button is clicked or if hard carriage return after message
              if((event.getSource() == (sendMsgButton)) || (event.getSource().equals(createMsg)))
                   //if theres no text dont send message
                   if(createMsg.getText().equals(""))
                        JOptionPane.showMessageDialog(this, "There's no text to send!");
                   else
                        String str  = createMsg.getText();
                        printMessage(str);
              //if the exit button is clicked
              if(event.getSource() == (exitButton))
                   //quit the chat app
                   JOptionPane.showMessageDialog(this, "Thanks For Using Elliot's Chat Network! \nSee You Again Soon!");
                   System.exit(0);
              //if the self comm option is turned on
              if(event.getSource() == (talk2urselfOn))
                   talktoself = true;
                   JOptionPane.showMessageDialog(this, "You have begun self communication \nmessages you send are now displayed");
              //if the self comm option is turned off
              if(event.getSource() == (talk2urselfOff))
                   talktoself = false;
                   JOptionPane.showMessageDialog(this, "You have stopped self communication \nmessages you send are no longer displayed");
              //for the normal font option
              if(fontcombiBox.getSelectedItem().equals("Plain"))
                   //makes a new font style plain...
                   conversationDisplay.setFont(new Font("simple", Font.PLAIN, 12));
                   createMsg.setFont(new Font("simple", Font.PLAIN, 12));
              //for the bold font option
              if(fontcombiBox.getSelectedItem().equals("Bold"))
                   conversationDisplay.setFont(new Font("simple", Font.BOLD, 12));
                   createMsg.setFont(new Font("simple", Font.BOLD, 12));
              //for the italic font option
              if(fontcombiBox.getSelectedItem().equals("Italic"))
                   conversationDisplay.setFont(new Font("simple", Font.ITALIC, 12));
                   createMsg.setFont(new Font("simple", Font.ITALIC, 12));
               *      //the status events if they didnt create null points...
              if(statusbox.getSelectedItem().equals("Online"))
                   String status = "<Online>";
                   printMessage(status);
              if(statusbox.getSelectedItem().equals("Away"))
                   String status = "<Away>";
                   printMessage(status);
              if(statusbox.getSelectedItem().equals("Be Right Back"))
                   String status = "<Be Right Back>";
                   printMessage(status);
              if(statusbox.getSelectedItem().equals("Busy"))
                   String status = "<Busy>";
                   printMessage(status);
              if(statusbox.getSelectedItem().equals("Out To Lunch"))
                   String status = "<Out To Lunch>";
                   printMessage(status);
              if(statusbox.getSelectedItem().equals("On The Phone"))
                   String status = "<On The Phone>";
                   printMessage(status);
              //the emoticons events...
              if(emoticons.getSelectedItem().equals("Angry"))
                   String status = "<Angry>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Sad"))
                   String status = "<Sad>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Shocked"))
                   String status = "<Shocked>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Happy"))
                   String status = "<Happy>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Crying"))
                   String status = "<Crying>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Laughing"))
                   String status = "<Laughing>";
                   printMessage(status);
              if(emoticons.getSelectedItem().equals("Laughing My Ass Off!"))
                   String status = "<Laughing My Ass Off!>";
                   printMessage(status);
              //if the colour button is clicked
              if(event.getSource() == colourButton)
                   //create a new colour chooser
                   colourchoo = new JColorChooser();
                   //create the dialog its shown in
                   JColorChooser.createDialog(colourButton, "Choose your background colour", true, colourchoo, this, this);
                   //now show the dialog
                   Color col = JColorChooser.showDialog(sendMsgButton, "Choose your background colour", Color.GRAY);
                   //when a colour is chosen it becomes the bg colour
                   theWholeApp.setBackground(col);
                   rpanel1.setBackground(col);
                   rpanel2.setBackground(col);
                   rpanel3.setBackground(col);
                   rpanel4.setBackground(col);
                   rpanel5.setBackground(col);
                   lpanel1.setBackground(col);
                   lpanel2.setBackground(col);
                   lpanel3.setBackground(col);
                   lpanel4.setBackground(col);
                   lpanel5.setBackground(col);
              //if the connect button is clicked
              if(event.getSource() == (connect))
                   //get the txt entered into ip addy field & port num fields with a text check...
                   if(hosty.getText().equals("") || portnumfd.getText().equals("") || nickName.getText().equals(""))
                        JOptionPane.showMessageDialog(this, "You cant connect! \nThis is because the either the \n0 - HostName\n 0 - Port Number \n0 - Your Nick \nIs Missing...");
                   else
                        //get details and connect
                        username = nickName.getText();
                        String ipay = hostfield.getText();
                        String porty = portnumfd.getText();
                        connectto(ipay,porty);
          * This method is similar to an append method in that it allows msgs recieved by the server to
          * be displayed in the conversation window. It also deals with the self comm mode as if its disabled
          * then no messages from the sender will be displayed.
         public void moveTextToConvo(String texty)
              //check
              if(ignoreyourself == true)
                   ignoreyourself = false;
              else
                   //If self comm is on the send message as normal
                   if(talktoself)
                        conversationDisplay.setText(conversationDisplay.getText() + texty);
                   else
                        //check message isnt sent by the current client - if it is ignore it!
                        if(texty.startsWith(nickName.getText()))
                             ignoreyourself = true;
                        else
                             conversationDisplay.setText(conversationDisplay.getText() + texty);
              //allows the scroll pane to move automatically with the conversation
              conversationDisplay.setCaretPosition(conversationDisplay.getText().length());
          * This method (connectto) is called if the button's clicked and also sets up a relation
          * between the client and clienttoserver class
         public void connectto(String ipa,String portNO)
              //portNO needs to be changed from string to int
              int portNum = new Integer(portNO).intValue();
              try
                   //creates a socket
                   socky = new Socket(ipa, portNum);
                   writer = new PrintWriter(socky.getOutputStream(), true);
                   ClienttoServer cts = new ClienttoServer(socky, this);
                   cts.runit();
                   //give user a prompt
                   JOptionPane.showMessageDialog(this, "You're now connected!");
              catch(UnknownHostException e)
                   System.err.println("Unknown host...");
                   //prompt the user
                   JOptionPane.showMessageDialog(this, "Failed to connect! \nPlease try again...");
              catch(IOException e)
                   System.err.println("Could Not Connect!");
                   //prompt user
                   JOptionPane.showMessageDialog(this, "Error! \nCould not connect - please try again!");
          * This method sends msgs from current client to server, sends username and then the message.
          * This is split into two different messages as the "\n" is used.
         public void printMessage(String mess)
              writer.println(usernamey.getText() + " says: \n" + mess);
              //then clear the text in the message creation area...
              createMsg.setText("");
          * Accessor method to retrieve userName
         public String getUName()
              return username;
          * Disconnect this user from the server so that they can no longer recieve/send messages
         public void dropconnection()
              try
                   //Start to close everything - informing user
                   writer.close();
                   socky.close();
                   //Give the user info on whats happening
                   JOptionPane.showMessageDialog(this, "You are now disconnected \nYou will no longer be able to \nsend and recieve messages");
                   System.out.println("A user has left the conversation...");
              catch (IOException e)
                   System.err.println("IOException " + e);
    The Server Class:
    import java.net.*;
    import java.io.*;
    * This class works in sync with the ServertoClient class in order to read
    * messages from clients and then send back out to all the active clients. Due to
    * the usage of threading multiple clients can use this server.
    * Once again some of this code is from Florians 2005 tutorial work.
    public class Server
         private ServerSocket server;
         private ServertoClient threads[];
         private static int portNo  = 2250;
         private static String Host = ""; //find method to retrieve ip
         private int maxPeeps = 20; //20 people can talk together but this can be altered
          * 1st Constructor - has no params
         public Server()
          * 2nd Constructor - allows for port number setting
         public Server(int portnumber)
              portNo = portnumber;
          * 3rd Constructor - allows for port number & max users
         public Server(int portnumber, int maxiusers)
              portNo = portnumber;
              maxPeeps = maxiusers;
          * This method is to constantly listen for possible messages from clients
         public void listener()
              //set the time out of method to just under a minute
              final int waitingTime = 500000000;
              //a boolean variable to keep it waiting
              boolean keepWait = true;
              //create a threads array of length maxpeeps
              threads = new ServertoClient[maxPeeps];
              //define a variable that will be used as a count of the no of threads
              int x = 0;
              try
                   //open a new socket on this port number
                   server = new ServerSocket(portNo);
              catch (IOException e)
                   System.err.println("IOException " + e);
                   return;
              //while the keepWait is true and the no. of threads is less than the max...
              while(keepWait && x < maxPeeps)
                   try
                        //set the timeout, this is the waitingTime (50 secs)
                        server.setSoTimeout(waitingTime);
                        //listen for connection to accept
                        Socket socky = server.accept();
                        System.out.println("A New User Has Connected");
                        //creates a new thread and adds it to array
                        threads[x] = new ServertoClient(this, socky);
                        //the thread begins
                        threads[x].start();
                   catch (InterruptedIOException e)
                        System.err.println("The Connection Timed Out...");
                        keepWait = false;
                   catch (IOException e)
                        System.err.println("IOException " + e);
                   x++; //increment no. of threads
              //if waitingTime is reached or there are too many threads then server closes
              try
                   server.close();
              catch(IOException e)
                   System.err.println("IOException " + e);
                   return;
          * This prints the string to all active threads
         public void printAll(String printy)
              for(int x = 0; x < threads.length; x++)
                   if(threads[x] !=null && threads[x].isAlive())
                        threads[x].sendMsg(printy);
          * Main method for the server, creates a new server and then continues to listen
          * for messages from different users
         public static void main(String[] args)
              Server chatsession = new Server();
              System.out.println("The Server Is Now Running on port NO: " + portNo);
              System.out.println("And IP Address: " + Host);
              chatsession.listener();
    [/code
    The ServertoClient Classimport java.lang.Thread;
    import java.net.*;
    import java.io.*;
    * This is the ClienttoServer class that acts as an intermediary between the server
    public class ClienttoServer extends Thread
         private Socket socky;
         private BufferedReader bready;
         private boolean active;
         private Client client;
         * This is the constructor to create a new client service
         public ClienttoServer(Socket socket, Client cli)
              socky = socket;
              active = false;
              client = cli;
              //try to read from the client
              try
                   bready = new BufferedReader(new InputStreamReader(socky.getInputStream()));
              catch (IOException e)
                   System.err.println("IOException " + e);
         * This method reads in from the client
         public void runit()
              active = true;
              while(active == true)
              {//continue to read in and then change the text in the conversation window
                   try
                        String message = bready.readLine();
                        client.moveTextToConvo(message + "\n");
                   catch (IOException e)
                        System.err.println("IOException " + e);
                        active = false;
    And finaly the servertoclient class
    import java.net.*;
    import java.io.*;
    import java.lang.Thread;
    * This clas provides the services that the server uses
    public class ServertoClient extends Thread
         private Socket socky;
         private Server server;
         private BufferedReader bready;
         private PrintWriter writer;
          * This constructor sets up the socket
         public ServertoClient(Server theServer, Socket theSocket)throws IOException
              socky = theSocket;
              server = theServer;
              //sets up the i/o streams
              writer = new PrintWriter(socky.getOutputStream(), true);
              bready = new BufferedReader(new InputStreamReader(socky.getInputStream()));
          * This method keeps listening until user disconnects
         public void run()
              boolean keepRunning = true;
              try
                   //keep listening 'til user disconnects
                   while(keepRunning = true)
                        final String tempmsg = bready.readLine();
                        //is there a message (if yes then print it!)
                        if(tempmsg == null)
                        else
                             server.printAll(tempmsg);
                   dropconnection();
              catch (IOException e)
                   System.err.println("IOException in thread " + Thread.currentThread() + ": " + e);
          * This method is for when a user disconnects from the server...
         public void dropconnection()
              try
                   bready.close();
                   writer.close();
                   socky.close();
              catch (IOException e)
                   System.err.println("IOException in thread " + Thread.currentThread() + ": " + e);
              System.out.println("A User Has Disconnected...");
          * This method prints the message
         public void sendMsg(String msg)
              writer.println(msg);
    }Thats it any help would be much appreciated
    Cheers.

    Like the previous poster indicated: try to find a minimal example that shows the error your experiencing.
    One thing that seems bogus is the Server.listener() method. For one thing, it can increment x even if no new connection has been established (e.g., x will be incremented if an exception is caught).

  • How to recover a Yoga tablet 2 with Windows 8.1

    How to : Recover a Yoga tablet 2 version with Windows 8.1 Bing 
    In case of emergency, if you need this option , or other circumstances ... last hope ..  
    ..works without keyboard ...
    Yoga tab 2 as tablet itself ...equipped with three manual function buttons ,means not so many possible options left ... 
    Front  Yoga Tablet 2 10" version with Windows 8.1
    Shows micro HDMI and headphone out Yoga Tablet 2 10" version with Windows 8.1
    Shows volume rockers and thumb on/off button
    first step keep in mind that your batteryis near fully charged, otherwise plug-in
    save your personal data on a cloud or microsdhc card. ..thats for save...
    Ok...lets go.... push the volume rocker up hold them and press the round button on three seconds.
    the  yoga tab 2 will start up and show the lenovo logo...
     a few seconds later this should be shown ...  
    novo menu
    Normal Startup
    BIOS Setup
    Boot Menu
    System Recovery
    simply touch System Recovery
    that will load the recovery envirement after the break ...
    a few seconds later the yoga screen turns into blue colour
    Choose an option
    Continue  (Exit and continue to Windows 8.1) 
    Use a device (Use a USB drive , network connection or Windows recovery DVD)
    Troubleshoot (Refresh or reset your PC , or use advanced tools) 
    Turn off your PC
    the right way to go is  Troubleshoot ... so give a big five to Troubleshoot... (a soft touch please )
    ...next screen is Troubleshoot...with these options
    Troubleshoot
    Refresh your PC
    If your PC isnt running well, you can refresh it without loosing your files
    Reset your PC
    If you want to remove all of your files you can reset your PC completely
    Advanced options
     touch Reset your PC
    will show this on your Yoga tab 2 .... 
    Here´s what will happen
    * All your personal files and applications will be removed
    * Your PC settings will be restored to their defaults
    touch  Next , after another start or cancel option... the recovery envirement need around an hour to recover ...
    tip toe tip toe ... walking around the block with your pet ... talk with your neighbour ... or something else ..
    Bing, Bong : time is up and your yoga is complete factory restored , so you can startin your yoga tab 2 from a scratch that welcomes you with windows welcome screen, touch it to set up your personal data and so on..
    Thinkies 2x X200s/X301 8GB 256GB SSD @ Win 7 64
    Ideas Centre A520 ,Yoga 2 256GB SSD,Yoga 2 tablet @ Win 8.1

    Excellent tip, K!
    Community Advocate Program Manager
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

Maybe you are looking for