FlowLayout and Jlabels and Jbuttons,  Help!!!!!

Ok, I have an Assignment using the FlowLayout only!!. I have been readin all the tutorials and documentation regarding the FlowLayout. Yet it seems I have a problem. Within my prrogram I am to position the buttons on the right and postion the text on the left.
My question is: Is there a way to postion each component separtely using FlowLayout. Can yoo position the Jlabels to the left and the JButtons to the right?
I know other layouts would be easier but our proffessor wants us to use the flowlayout for this assignment.
Here is my code
import javax.swing.*;
import java.awt.*;
import java.awt.FlowLayout;
import java.awt.Font;
               public class VideoStore extends JFrame {
                    JButton b1, b2, b3;
                    JLabel movie1,movie2,movie3,header;
               public VideoStore (String title) {
                    super (title);
                    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    FlowLayout video = new FlowLayout(FlowLayout.LEFT);
                   setLayout(video);
                    header = new JLabel("CCAC VideoStore");
                    header.setFont(new Font("Times New Roman", Font.BOLD, 24));
                   add(header);
                   {movie1= new JLabel("Johnson Family Vacation");
                   movie1.setFont(new Font("Courier New", Font.BOLD, 14));
                    add(movie1);
                    b1= new JButton("Buy");
                    video.setAlignment(FlowLayout.RIGHT);
                    add(b1);}
                    movie2= new JLabel("PitchBlack");
                        movie2.setFont(new Font("Courier New", Font.BOLD, 14));
                   add(movie2);
                    b2 = new JButton ("Buy");
                    add(b2);
                    movie3= new JLabel ("Meet The Fockers");
                   movie3.setFont(new Font("Courier New", Font.BOLD, 14));
                   add(movie3);
                    b3 = new JButton ("Buy");
                    add(b3);
               }Edited by: ConfusedNewb on Apr 20, 2010 8:10 AM

ConfusedNewb wrote:
Sorry.Requirements are: All of the "Buy" JButtons need aligned to the right and all of the JLabels need aligned to the left. There are 3 movie Jlabels and 3 jbuttons. I just cant get them to align without using the spacing trick. Everything has to fit in one window.This should be layed out with 2 JPanels, one for the Labels and one for the Buttons. Since FlowLayout will lay the 2 JPanels side by side, you will get the separation that you need. You just need to justify the Label and Button Panels appropriately and make the outer container and Panels appropriate widths to allow the layout to function as you need.

Similar Messages

  • Getting values from JLabel[] with JButton[] help!

    Hello everyone!
    My problem is:
    I have created JPanel, i have an array of JButtons and array of JLabels, they are all placed on JPanel depending from record count in *.mdb table - JLabels have its own value selected from Access table.mdb! I need- each time i press some button,say 3rd button i get value showing from 3rd JLabel in some elsewere created textfield, if i have some 60 records and 60 buttons and 60 labels its very annoying to add for each button actionlistener and for each button ask for example jButton[1].addActionListener() ...{ jLabel[1].getText()......} and so on!
    Any suggestion will be appreciated! Thank you!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        final int ROWS = 10;
        JPanel[] rows = new JPanel[ROWS];
        final JLabel[] labels = new JLabel[ROWS];
        JButton[] buttons = new JButton[ROWS];
        JPanel p = new JPanel(new GridLayout(ROWS,1));
        final JTextField tf = new JTextField(10);
        ActionListener listener = new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            tf.setText(labels[Integer.parseInt(((JButton)ae.getSource()).getName())].getText());
        for(int x = 0; x < ROWS; x++)
          labels[x] = new JLabel(""+(int)(Math.random()*10000));
          buttons[x] = new JButton("Button "+x);
          buttons[x].setName(""+x);
          buttons[x].addActionListener(listener);
          rows[x] = new JPanel(new GridLayout(1,2));
          rows[x].add(labels[x]);
          rows[x].add(buttons[x]);
          p.add(rows[x]);
        JFrame f = new JFrame();
        f.getContentPane().add(p,BorderLayout.CENTER);
        f.getContentPane().add(tf,BorderLayout.SOUTH);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • JLabel and JButton

    I got my clock hands issue figured out, now I am trying to get a JButton and JLabels and JTextboxes in. I think I have the code for the labels right, but nothing shows up....any suggestions or places for me to look for help?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class clocky extends Frame {
         public static void main(String args[])
                   Frame frame = new clocky();
                   frame.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent we){
                             System.exit(0);
                   frame.setSize(300, 300);
                   frame.setVisible(true);
         private void createButton()
              JButton button = new JButton("Show Time");
         private void labels()
         JLabel hourLabel = new JLabel("Hour: ", JLabel.LEFT);
         hourLabel.setVerticalAlignment(JLabel.TOP);
         JLabel minLabel = new JLabel("Minute: ", JLabel.LEFT);
         minLabel.setVerticalAlignment(JLabel.TOP);
         final int centerX = 150;
         final int centerY = 180;
         Shape circle = new Ellipse2D.Double(50, 80, 200, 200);
         public void paint(Graphics g)
              Graphics2D ga = (Graphics2D)g;
              ga.draw(circle);
              //mins hand 6
              //ga.drawLine(150, 90, centerX, centerY); //00     +90 -90
              ga.drawLine(240, 180, centerX, centerY); //15      +90 +90
              //ga.drawLine(150, 270, centerX, centerY); //30      -90 +90
              //ga.drawLine(60, 180, centerX, centerY); //45      -90 -90
         //hrs hand 2.66666666
              ga.drawLine(150, 140, centerX, centerY); //00          +40 -40
              //ga.drawLine(190, 180, centerX, centerY); //15           +40 +40
              //ga.drawLine(150, 220, centerX, centerY); //30           -40 +40
              //ga.drawLine(110, 180, centerX, centerY); //45           -40 -40
    }

    >
    I got my clock hands issue figured out, now I am trying to get a JButton and JLabels and JTextboxes in. I think I have the code for the labels right, >You have methods to create buttons and labels, but nothing calls those methods, and even if hey were called, the created components are added to no container, and are lost at the end of the method.
    >
    ..but nothing shows up....>Wrong, the clock face painted directly to the JFrame shows. And that brings me to the second point. If you added those components to a frame that overrides paint, they will disappear. Once you override paint, it is up to you to paint everything that needs painting.
    This is why I would rethink your entire strategy. Override paintComponent(Graphics) in a ClockFace that extends JPanel. ClockFace should also set or override the preferred size. Then add the ClockFace object to another JPanel(s) (e.g. mainPanel) containing the JButton(s), JLabel(s) and ClockFace. Finally, add an EmptyBorder around mainPanel, and set it as the content pane of the JFrame.
    And please remember to use the 'code' tags to keep code formatted. To achieve that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.

  • Having some problems with ImageIcons and JLabels

    I'm making a checkers game, and so far it's going pretty well.
    I've got the basic game down, and you can move pieces, jump, your turn ends when you can't jump anymore, etc...
    However, I've had three problems:
    1.) I'm using JLabels to display my board (8 x 8.. well actually 9 x 9 for an outer row labelled A,B,C,D.. 1,2,3,4...) Anyway, I create the JLabels using something that looks like \:
    JLabel square = new JLabel(new ImageIcon("pic.png"));
    Now, the picture loads properly, but it seems like the picture is being cropped, and the top and bottom are getting chopped off, so my 36 x 36 pixel *.gif appears to be 36 x 30.
    You can see how there is a gap created in:
    http://img235.imageshack.us/img235/7765/prob13ky.jpg
    Now the problem may be with the GridLayout I am using, but I set the distance between the components in the container to be 0, 0 so I don't think that GridLayout is chopping my icons. I've also tried setPreferredSize(new Dimension(36,36))
    for both my ImageIcons and JLabels and for my container (which I set to size 2000,2000, just to make sure there was room). If anyone can help me, it's be appreciated.
    2.) I used to be able to view my outside row/column of squares that said A,B,C,D.... and 1,2,3,4... with the square in the corner having a random pic. For some reason now (have no clue why) I now see only the pic in the corner, and then a little gray smudge diagonally under it.
    Pic:
    http://img347.imageshack.us/img347/8308/prob24im.jpg
    I don't know what's wrong. I'm pretty sure it's none of the new methods I've written, as those are all in my static void main (String[] ar) ...... and if I comment all the methods in my main except where I first make the JFrame and set it visible, it still turns out like that. repaint() doesn't help.
    3.) For some reason, when I move another window (AIM, the console window, etc...) over my Swing window, it "erases" (turns gray, just wipes clean) the part where I have my squares that have pieces.
    What's weird is that:
    The border pieces (err.. my one visible corner piece from my second problem) don't get wiped, and some debugging text and JLabels (in a different JPanel) are fine. I don't think the JPanel matters though; the border pieces and the playing squares (which get wiped) are in the same JPanel and same array of squares.
    repaint(); also erases ALL of my playing squares, whereas moving a window over them would only erase the part that the window covered.
    Also, I added a mouseListener so that whenever I move the mouse over a square, it changes the image (to a tinted version, so you know the mouse is over it) and when you move the mouse away, it returns to normal. However, if I wildly swing the mouse around the area, it seems to lock up and freeze for a few seconds. Is there anything I can do to prevent this??
    Thanks in advance.

    It is hard to tell what your problems are without any code at all (I saw your images, but that doesn't make it easy to see what is wrong in your code). If you do post code, please use code tags (see button above posting box).
    I've seen your MouseListener problem before--we had the exact same issue in our code at work. It would freeze up while it processed all of the mouse events (unbearably slow). I'm not at work right now, so I don't recall how it was fixed. Essentially, you need to only process the event periodically. You need to only update the image if the mouse switches squares. Or, only update the image if the distance from the last mouse event is more than some specified amount. We might also have checked the time difference between mouse events before processing a new one. I could look at the code at work tomorrow, if you are still having trouble.

  • Creating a gridlayout of jlabels and jbuttons in a JPanel

    The assignment:
    "Create a JPanel that contains an 8x8 checkerboard. Make all of the red squares JButtons and be sure to add them to the JPanel. Make all of the black squares JLabels and add them to the JPanel. Don't forget, you must use the add method to attach the JPanel to the JApplet's contentPane but that there is no contentPane for a JPanel. Be sure to set up any interfaces to handle the JButtons. Use a GridLayout to position and size each of the components instead of absolute locations and sizes."
    This assignment introduces the JPanel to me for the first time, I have not seen what the JDialog and JFrame are.
    What I have:
    import java.awt.*;
    import javax.swing.*;
    * Class CheckerBoard - write a description of the class here
    * @author (your name)
    * @version (a version number)
    public class CheckerBoard extends JPanel
        JButton redSquare;
        JLabel blackSquare;
         * Called by the browser or applet viewer to inform this JApplet that it
         * has been loaded into the system. It is always called before the first
         * time that the start method is called.
        public void init()
            JPanel p = new JPanel();
            setLayout(new GridLayout(8,8));
            setSize(512,512);
            ImageIcon red = new ImageIcon("GUI-006-RedButton.png");
            ImageIcon black = new ImageIcon("GUI-006-BlackSquare.png");
            blackSquare = new JLabel(black);
            blackSquare.setSize(64,64);
            redSquare = new JButton(red);
            redSquare.setSize(64,64);
            for (int i = 0; i < 64; i++) {
                if ((i % 2) == 1)
                    add(blackSquare);
                else
                   add(redSquare);
            // this is a workaround for a security conflict with some browsers
            // including some versions of Netscape & Internet Explorer which do
            // not allow access to the AWT system event queue which JApplets do
            // on startup to check access. May not be necessary with your browser.
            JRootPane rootPane = this.getRootPane();   
            rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
    }After successfully compiling it when I try to run it there appears to be nothing to run. I've tried messing around with content panes but I'm not sure if I need to add one for this assignment at all.

    Some suggestions:
    1) First and foremost, read about JPanels, JApplets, and JFrames. None of the help you can get here will substitute for your applying yourself towards this, absolutely none, and judging by your code, you have your work cut out for you.
    2) Don't have your JPanel initialize with an init method, that's what Applets and JApplets do. Instead have it initialize with a proper constructor.
    3) I'm wondering if your "workaround" code belongs in the JApplet that contains the JPanel and not in the JPanel. It has nothing to do with the JPanel's mission. For instance, what if you later decide to place this panel into a JFrame?
    4) Avoid "setSize", and if at all possible, use "setPreferredSize" instead. You are working with LayoutManagers who do the size setting. You are best served by suggesting the size to them.
    5) Please ask specific questions. Just dumping your code without a question is considered quite rude here. We are all volunteers. If you want our free advice, you really should be considerate enough to make it easy for us to help you.
    Good luck.
    Edited by: Encephalopathic on Dec 21, 2007 6:14 PM

  • Help with JLabels and JTextFields

    I'm experimenting with JLabels and JTextFields in a basic JFrame. What I am trying to accomplish (without success) is to align a JLabel above and centered on a JTextField. The tutorials are confusing me. Any help would be greatly appreciated. a Sample of code is ...
    JLabel  myTextLabel = new JLabel("Who's text Field?");
    JTextField myTextField = new JTextField("My Text Field");...after reading the tutorial I thought that I needed to assign L&F variables to the JLabel ... i.e.
    JLabel myTextLabel = new JLabel("Who's text field?:", JLabel.CENTER, JLabel.TOP); but this results in an error when compiling. (cannot find symbol), so I thought I need to assign the JLabel to the JTextField. i.e.
    myTextLabel.setLabelFor(myTextField);Then I get "identifier" expected. So now being completely confused I am here asking "How do I?" :)
    Thanks in advance!

    Most likely, you need to think a little more about using a layout manager to hlp you along the way. If memory serves, the default layout manager for a JPanel is FlowLayout and that will simply place the components you add to the panel one after another and allow each to adopt it's preferred size.
    One way to ensure that the two compoenets were sized equally, would be to use the GridLayout layout manager and create either one row with two columns, or two rows with one column on each. Then add the compoennets to each of the 'cells' so to speak and that should ensure that they are both the same size.
    As to making the text centered in each, both the JLabel and JtextField classes have amethod called setHorizontalAlignment(); it can be used to aligh the text as you require.
    Simply create an instance of the class;
    JLabel aLabel = new JLabel("Some Text");
    // Then set the alignment
    aLabel.setHorizontalAlignment(SwingConstants.CENTER);Or, do the whole operation i one step
    JLabel aLabel = new JLabel("Sone Text", SwingConstants.CENTER);and then add the componenet to the panel once you have set the layout manager.
    Remember that the label.textfield will have to be wide enought to make it obvious that the text is centered!

  • Left- and right-justifying with dot leaders in JLabel and JButton

    Hi,
    I am developing checklists using JLabel and JButton components and want to finish up with the text in each component looking something like the following (each line is a separate button/label):
    ACTION No1............................RESPONSE No1
    ACTION No2............................RESPONSE No2
    ACTION No3............................RESPONSE No3
    The idea is to have the �Action� text left-justified and the �Response� text right-justified with dot-leaders as shown.
    Each text line will be put into its own fixed length label or button.
    I plan to construct a string from text blocks �ACTION No1� and �RESPONSE No1� and add the calculated, exact no of dots in between to fill the space.
    The text font can be fixed (e.g. Courier) or proportional (e.g. Arial).
    My question is how to calculate the number of dots to add to fill the space for different fonts and font sizes.
    I think that using FontMetrics could provide some help but am not sure how this would work.
    Can anyone help.
    Many tks
    John

    Hi,
    I've developed your suggested code further to enable selected JLabels to be toggled visible(true/false) by pressing a JButton.
    I'd like however that when a label is made invisible that the rest of the labels/buttons move up to fill the space left by the now invisible label and vice versa.
    How do I do this, can you enlighten me on a solution?
    Modified code included below. Not very elegant but serves to illustrate the point in question and only makes the label invisible.
    Many tks
    John
    package componentwierd;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ComponentWierd extends JFrame implements ComponentListener, ActionListener {
        boolean isVisible = true;
        JLabel label2 = new JLabel();
        public ComponentWierd() {
            getContentPane().setLayout( new GridLayout(0, 1) );
            // Using my original suggestion
            JLabel label = new JLabel();
            label.setLayout(new BorderLayout());
            label.add(createWierdComponent());
            getContentPane().add(label);
            JButton button = new JButton();
            button.setLayout(new BorderLayout());
            button.add(createWierdComponent());
            button.addActionListener(this);
            getContentPane().add(button);
            // Using Font Metrics
            // JLabel label2 = new JLabel("Label2 West...Label2 East");
            label2.setText("Label2 West...Label2 East");
            label2.addComponentListener( this );
            getContentPane().add(label2);
            JButton button2 = new JButton("Button2 West...Button2 East");
            System.out.println(button2.getIconTextGap());
            button2.addComponentListener( this );
            button2.setVisible(true);
            getContentPane().add(button2);
        public void actionPerformed(ActionEvent e) {
            if (isVisible == true) {
                isVisible = false;
                label2.setVisible(false);
            } else if (isVisible == false) {
                isVisible = true;
                label2.setVisible(true);
        private JComponent createWierdComponent() {
            JPanel panel = new JPanel(new BorderLayout());
            panel.setOpaque( false );
            panel.add(new JLabel("Label WEST"), BorderLayout.WEST);
            panel.add(new JLabel("..............................................."));
            panel.add(new JLabel("Label EAST"), BorderLayout.EAST);
            return panel;
        public void componentResized(ComponentEvent e) {
            if (e.getComponent() instanceof JLabel) {
                JLabel component = (JLabel)e.getComponent();
                String text = component.getText();
                String fitText = fitText(component, text);
                component.setText( fitText );
            if (e.getComponent() instanceof JButton) {
                JButton component = (JButton)e.getComponent();
                String text = component.getText();
                String fitText = fitText(component, text);
                component.setText( fitText );
        private String fitText(JComponent component, String text) {
            // Calculate the total width for painting the text
            // (Not sure why I need the -8)
            Insets insets = component.getInsets();
            int availableWidth = getWidth() - insets.left - insets.right - 8;
            // Calculate the minimum width our text will take
            String start = text.substring(0, text.indexOf("."));
            String middle = "...";
            String end = text.substring(text.lastIndexOf(".") + 1);
            FontMetrics fm = getFontMetrics( component.getFont() );
            int startWidth = fm.stringWidth( start );
            int middleWidth = fm.stringWidth( middle );
            int endWidth = fm.stringWidth( end );
            int minimumWidth = startWidth + middleWidth + endWidth;
            // Add dots to fill out the extra space
            StringBuffer buffer = new StringBuffer(start);
            buffer.append(middle);
            if (minimumWidth < availableWidth) {
                String dot = ".";
                int dotWidth = fm.stringWidth( dot );
                int dots = (availableWidth - minimumWidth) / dotWidth;
                for (int i = 0; i < dots; i++) {
                    buffer.append( dot );
            buffer.append(end);
            String result = buffer.toString();
            return result;
        public void componentHidden(ComponentEvent e) {}
        public void componentMoved(ComponentEvent e) {}
        public void componentShown(ComponentEvent e) {}
        public static void main(String[] args) {
            ComponentWierd frame = new ComponentWierd();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.setSize(200, 200);
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

  • How to print JTextPane containing JTextFields, JLabels and JButtons?

    Hi!
    I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
    I wrote this small programm to demonstrate my problem:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.print.PrinterException;
    public class TextPaneTest2 extends JFrame {
         private void insertStringInTextPane(String text,
                   StyledDocument doc) {
              try {
                   doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
              catch (BadLocationException x) {
                   x.printStackTrace();
         private void insertTextFieldInTextPane(String text,
                   JTextPane tp) {
              JTextField tf = new JTextField(text);
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(tf);
         private void insertButtonInTextPane(String text,
                   JTextPane tp) {
              JButton button = new JButton(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(button);
         private void insertLabelInTextPane(String text,
                   JTextPane tp) {
              JLabel label = new JLabel(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(label);
         public TextPaneTest2() {
              StyledDocument doc = new DefaultStyledDocument();
              StyledDocument printDoc = new DefaultStyledDocument();
              JTextPane tp = new JTextPane(doc);
              JTextPane printTp = new JTextPane(printDoc);
              this.insertStringInTextPane("Text ", doc);
              this.insertStringInTextPane("Text ", printDoc);
              this.insertTextFieldInTextPane("Field", tp);
              this.insertTextFieldInTextPane("Field", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertButtonInTextPane("Button", tp);
              this.insertButtonInTextPane("Button", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertLabelInTextPane("Label", tp);
              this.insertLabelInTextPane("Label", printTp);
              this.insertStringInTextPane(" Text Text", doc);
              this.insertStringInTextPane(" Text Text", printDoc);
              tp.setEditable(false);
              printTp.setEditable(false);
              this.getContentPane().add(tp);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible(true);
              JOptionPane.showMessageDialog(tp, "Start printing");
              try {
                   tp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
              try {
                   printTp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new TextPaneTest2();
    }First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
    Thanks!

    I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.

  • How do I chance the place of JLabel and JButton in JPanel.

    I'm using DefaultLayout and I want to give the user the ability to change the place of JLabel and JButton. I managed the DnD part, but when "dropped" the control returns to it's original position.
    I tried using setX() and setY().

    You need to use a null Layout, also known as [url http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]Absolute Positioning

  • Color of JLabel and JButton text

    Hi,
    Could someone tell me how to set the color of JLabels and JButton text.
    Thanks

    for JButton text
    myButton.setForeground(Color.yellow);
    for JLabel
    myLabel.setForeground(Color.green);

  • Using clone() with JLabel and JButtons

    I need to find a way of making a duplicate copy of objects that extend JLabel and JButton. Do I need to implement the clone() methord manually, or is there a simpler way of doing this?

    Use a BorderLayout as the main layout. Add the two tables to the WEST and EAST.
    Create another panel using a different layout, maybe a vertical BoxLayout. Add the two buttons and then add this panel to the CENTER of the main panel.
    The secret is to nest different panels with different layout managers to achieve your desired layout.

  • Having probelm with JLabel and setText

    I posted a message in Java Programming but I think it will be more appropriate here. I am trying to create a calculator so I want my JLabel(output) to display the number of the button that is clicked on. I used output.setText("7") but I get an error when compiling saying <identifier> expected. Any advice would be great. Also, is there a getText method in JLabel? I need to concatenate the current contents of JLabel and the value of the button pushed. For example:
    output.setText( output.getText() + "7" );
    Anyways, here is my code. I tried to make it indent so it is easier to read but it doesn't show up once I post it.
    Thanks for you help.
    * Write a description of class calculator here.
    * @author (Jeremy Kruer)
    * @version (11/19/02)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class calculator extends JFrame
    private JButton one, two, three, four, five, six, seven, eight, nine, zero, dec, eq, plus, minus, mult, div;
    private JLabel output;
    private Container container;
    //set up GUI
    public calculator()
    //Create Title
    super("Calculator");
    //Set size and make visible
    setSize( 400, 400 );
    setVisible( true );
    container = getContentPane();
    container.setLayout( new FlowLayout() );
    //set up output
    output = new JLabel();
    container.add( output );
    //set up seven and register its event handler
    seven = new JButton( " 7 " );
    seven.addActionListener(
    //anonymouse inner class
    new ActionListener()
    //add a seven to the output diplay when clicked
    output.setText( "7" );
    }//end anonymouse inner class
    ); //end call to addActionListener
    container.add( seven );
    //set up eight
    eight = new JButton( " 8 " );
    container.add( eight );
    //set up nine
    nine = new JButton( " 9 " );
    container.add( nine );
    //set up div
    div = new JButton( " / " );
    container.add( div );
    //set up four
    four = new JButton( " 4 " );
    container.add( four );
    //set up five
    five = new JButton( " 5 " );
    container.add( five );
    //set up six
    six = new JButton( " 6 " );
    container.add( six );
    //set up mult
    mult = new JButton( " * " );
    container.add( mult );
    //set up one
    one = new JButton( " 1 " );
    container.add( one );
    //set up two
    two = new JButton( " 2 " );
    container.add( two );
    //set up three
    three = new JButton( " 3 " );
    container.add( three );
    //set up minus
    minus = new JButton( " - " );
    container.add( minus );
    //set up zero
    zero = new JButton( " 0 " );
    container.add( zero );
    //set up dec
    dec = new JButton( " . " );
    container.add( dec );
    //set up eq
    eq = new JButton( " = " );
    container.add( eq );
    //set up plus
    plus = new JButton( " +" );
    container.add( plus );
    //Set size and make visible
    setSize( 220, 250 );
    setVisible( true );
    //execute application
    public static void main( String args[] )
    calculator application = new calculator();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    // not tested but try it ...
    1. put an empty string into the JLabel
    declare
    String labString = "";
    (and declare the JLabel too)
    2. initialise label - init() {
    myLabel = new JLabel(labString)
    3. activate
    actionPerformed(ActionEvent evt) {
    if (evt.getSource()==button#7) {
    labString = getActionCommand();
    myLabel.setText(labString);
    validate();
    Something like that anyway - it should work + if you 'play' with it, you can probably make it a bit more efficiently than the methods I've outlined here.

  • How do I hide JLabel and TextField???

    I am trying to hide my start JLabels and TextFields. I thought that if I use an if statement it would work but it doesn't. I have been at this for awhile now. So here I am. Any help would help a lot.
    Thanks,
    Roman03
    JLabel inName = new JLabel("Enter Your Name: ");
    JLabel pName;
    TextField inText = new TextField( 14 );
    JLabel outText = new JLabel();
    public mainStation()
         getContentPane().setLayout( new FlowLayout() );
         if ( name == 0 )
         getContentPane().add( inName );
         getContentPane().add( inText );
         getContentPane().add( outText );     
         inText.addActionListener( this );
    void copyText()
    Characters newName = new Characters( inText.getText() );
    outText.setText( newName.someName() );
    public void actionPerformed( ActionEvent evt )
         name = name + 1;
         copyText();
         repaint();

    inName.setVisible(false);

  • Calculating Login and Logout Times - need help

    Hi everyone. I have the first part of this code and can't seem to figure out the time calculation part. What it is - create a code that asks for a user name or social security number, then the person enters up to 6 login and logout times for the day. They also have the option to enter personal time or sick time (neither of which can be over 8 hours). I have all of that complete, but I can't figure out how to get the in and out times and the leave times to calculate. I have 3 pieces of code - here they are:
    Hours:
    import java.util.*;
    public class Hours
         //define states of Hours
         int regularhoursInt = 0;
         int regularminutesInt = 0;
         int overtimehoursInt = 0;
         int overtimeminutesInt = 0;          
         //set hours worked
         public void setHours(int timein, int timeout)
              int temphoursin = timein/100;
              int tempminutesin = timein - timein/100;
              int temphoursout = timeout/100;
              int tempminutesout = timeout - timeout/100;
              GregorianCalendar time1 = new GregorianCalendar(2003, 8, 1, temphoursin, tempminutesin, 0);
              GregorianCalendar time2 = new GregorianCalendar(2003, 8, 1, temphoursout, tempminutesout, 0);
              //store to date
              Date d1 = time1.getTime();
              Date d2 = time2.getTime();
              //store time to long
              long t1 = d1.getTime();
              long t2 = d2.getTime();
              //subtract and convert to seconds
              long time = (t2 - t1)/1000;
              long tempregularLong = 0;
              long tempovertimeLong = 0;
              //see if regular hours are over 8 hours (28800 seconds)
              tempregularLong = time;
              if (tempregularLong > 28800)
                   tempovertimeLong = tempregularLong - 28800;
                   tempregularLong = tempregularLong - tempovertimeLong;
              //convert to hours and minutes
              regularhoursInt = regularhoursInt + (Integer.parseInt(Long.toString(tempregularLong)) / 3600);
              regularminutesInt = regularminutesInt + (Integer.parseInt(Long.toString(tempregularLong)) / (3600 * regularhoursInt));
              overtimehoursInt = overtimehoursInt + (Integer.parseInt(Long.toString(tempovertimeLong)) / 3600);
              overtimeminutesInt = overtimeminutesInt + (Integer.parseInt(Long.toString(tempovertimeLong)) / (3600 * regularhoursInt));     }
         // get regular hours worked
         public int getRegularHours()
              return regularhoursInt;
         // get regular minutes worked
         public int getRegularMinutes()
              return regularminutesInt;
         //get overtime hours worked
         public int getOvertimeHours()
              return overtimehoursInt;
         // get overtime minutes worked
         public int getOvertimeMinutes()
              return overtimeminutesInt;
    Employee:
    public class Employee
         //define states of employee
         String nameString = "";
         String ssnString = "";
         double payrateDouble = 0;
         double hoursworkedDouble = 0;
         double overtimehoursDouble = 0;
         double sickleaveDouble = 0;
         double personalleaveDouble = 0;
         double totalpayDouble = 0;
         //set and get employee name
         public void setName(String name)
              nameString = name;
         public String getName()
              return nameString;
         //set and get employee ssn
         public void setSsn(String ssn)
              ssnString = ssn;
         public String getSsn()
              return ssnString;
         //set and get employee payrate
         public void setPayRate(double payrate)
              payrateDouble = payrate;
         public double getPayRate()
              return payrateDouble;
         //set and get employee hours worked
         public void setHoursWorked(double hoursworked)
              hoursworkedDouble = hoursworked;
         public double getHoursWorked()
              return hoursworkedDouble;
         //set and get employee overtimehours
         public void setOverTime(double overtime)
              overtimehoursDouble = overtime;
         public double getOverTime()
              return overtimehoursDouble;
         //set and get employee sick leave hours
         public void setSickLeave(double sickleave)
              sickleaveDouble = sickleave;
         public double getSickLeave()
              return sickleaveDouble;
         //set and get employee sick leave hours
         public void setPersonalLeave(double personalleave)
              personalleaveDouble = personalleave;
         public double getPersonalLeave()
              return personalleaveDouble;
         //get employees total pay
         public double getTotalPay()
              //calculate regular pay
              totalpayDouble = payrateDouble * hoursworkedDouble;
              //add in any over time pay
              totalpayDouble = totalpayDouble + payrateDouble * 1.5 * overtimehoursDouble;
              //add in any sick time pay
              totalpayDouble = totalpayDouble + payrateDouble * sickleaveDouble;
              //add in any personal leave time pay
              totalpayDouble = totalpayDouble + payrateDouble * personalleaveDouble;
              return totalpayDouble;
    Entry Screen:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    //create entryscreen class as a java applet
    public class EntryScreen extends Applet implements ActionListener
         //declare all variables, labels, textfields, and buttons
    //store pay rate to variable payrateDouble
         double payrateDouble = 10.00;
         //store ssn and names to ssnString
         String[][] ssnString ={{"123121234", "234232345", "345343456", "456454567",
              "567565678", "678676789"},{"Jane Doe", "John Doe", "Sam Smith", "Tom Thumb", "Sara Jane", "Cindy Thompson"}};
         //set date format to MM/dd/yy and store in variable formatter
         SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
         //store current date to variable date
         Date date = new Date();
         //using variable formatter store current date to dateString
         String dateString = formatter.format(date);
         //declare all label, Textfields and buttons use in the applet
         JLabel titleLabel;
    JLabel dateLabel;
    JTextField dateTextField;
    JLabel ssnLabel;
    JTextField ssnTextField;
    JLabel timeLabel;
    JLabel inLabel;
    JLabel outLabel;
    JTextField in1TextField;
    JTextField in2TextField;
    JTextField in3TextField;
         JTextField in4TextField;
         JTextField in5TextField;
    JTextField in6TextField;
    JTextField out1TextField;
    JTextField out2TextField;
    JTextField out3TextField;
    JTextField out4TextField;
    JTextField out5TextField;
    JTextField out6TextField;
    JLabel sickLabel;
    JTextField sickTextField;
    JTextField personalTextField;
    JLabel personalLabel;
    JButton okButton;
    JButton clearButton;
    JLabel day1Label;
    JLabel day2Label;
    JLabel day3Label;
    JLabel day4Label;
    JLabel day5Label;
    JLabel day6Label;
         //initialize the applet screen
    public void init()
              //create a custom layout object based on the EntryScreenLayout class
              EntryScreenLayout customLayout = new EntryScreenLayout();
              //set the font for the screen
    setFont(new Font("Helvetica", Font.PLAIN, 12));
    setLayout(customLayout);
         //populate the applet with the labels, textfields, and buttons
              titleLabel = new JLabel("Employee Payroll System");
    add(titleLabel);
    dateLabel = new JLabel("Date (MM/DD/YY):");
    add(dateLabel);
    dateTextField = new JTextField("");
    add(dateTextField);
              //set text in field to current date
              dateTextField.setText(dateString);
    ssnLabel = new JLabel("SSN (Numbers Only):");
    add(ssnLabel);
    ssnTextField = new JTextField("");
    add(ssnTextField);
    timeLabel = new JLabel("Hours Worked (hhmm)");
    add(timeLabel);
    inLabel = new JLabel("In:");
    add(inLabel);
    outLabel = new JLabel("Out");
    add(outLabel);
    in1TextField = new JTextField("");
    add(in1TextField);
    in2TextField = new JTextField("");
    add(in2TextField);
    in3TextField = new JTextField("");
    add(in3TextField);
    in4TextField = new JTextField("");
    add(in4TextField);
    in5TextField = new JTextField("");
    add(in5TextField);
    in6TextField = new JTextField("");
    add(in6TextField);
    out1TextField = new JTextField("");
    add(out1TextField);
    out2TextField = new JTextField("");
    add(out2TextField);
    out3TextField = new JTextField("");
    add(out3TextField);
    out4TextField = new JTextField("");
    add(out4TextField);
    out5TextField = new JTextField("");
    add(out5TextField);
    out6TextField = new JTextField("");
    add(out6TextField);
    sickLabel = new JLabel("Sick Leave Used:");
    add(sickLabel);
    sickTextField = new JTextField("");
    add(sickTextField);
    personalTextField = new JTextField("");
    add(personalTextField);
    personalLabel = new JLabel("Personal Leave Used:");
    add(personalLabel);
         okButton = new JButton("Ok");
         add(okButton);
              okButton.addActionListener(this);
         clearButton = new JButton("Clear");
         add(clearButton);
              clearButton.addActionListener(this);
         day1Label = new JLabel("Day 1:");
         add(day1Label);
         day2Label = new JLabel("Day 2:");
         add(day2Label);
    day3Label = new JLabel("Day 3:");
    add(day3Label);
    day4Label = new JLabel("Day 4:");
    add(day4Label);
    day5Label = new JLabel("Day 5:");
    add(day5Label);
    day6Label = new JLabel("Day 6:");
              add(day6Label);
              //set the size of the applet window as listed in the EntryScreenLayout class
              setSize(getPreferredSize());
         public void actionPerformed(ActionEvent e)
              //get the source object
              Object source = e.getSource();
              //perform if OK button was presses      
              if(source == okButton)
                   int[][] inouttimes = new int[1][5];
                   boolean matchBoolean = false;
                   boolean timeError = false;
                   int locationInt = 0;
                   double[] leavehours = new double[1];
                   String messageString = "";
                   //get the text from the ssnTextField and store to inputString
                   String inputString = ssnTextField.getText();
                   //check to see if inputString matches ssnString array
                   for(int i = 0; i < 6; ++i)
                        //if a match assign variables
                        if (inputString.equals(ssnString[0]))
                             matchBoolean = true;
                             locationInt = i;
                             break;
                        //if not a match
                        else
                             matchBoolean = false;
                   }//end for i
                   //if a SSN match is true than display the name, SSN, total hours, overtime hours, and total pay for hours worked.
                   if (matchBoolean == true)
                        //get the check in/out times, if blank assign a zero
                        Employee temp = new Employee();
                        temp.setName(ssnString[1][locationInt]);
                        temp.setSsn(ssnString[0][locationInt]);
                        temp.setPayRate(payrateDouble);
                        temp.setSickLeave(Double.parseDouble(sickTextField.getText()));
                        temp.setPersonalLeave(Double.parseDouble(personalTextField.getText()));
                        /*inouttimes[0][0] = Integer.parseInt(in1TextField.getText());
                        inouttimes[1][0] = Integer.parseInt(out1TextField.getText();
                        inouttimes[0][1] = Integer.parseInt(in2TextField.getText();
                        inouttimes[1][1] = Integer.parseInt(out2TextField.getText();
                        inouttimes[0][2] = Integer.parseInt(in3TextField.getText();
                        inouttimes[1][2] = Integer.parseInt(out3TextField.getText();
                        inouttimes[0][3] = Integer.parseInt(in4TextField.getText();
                        inouttimes[1][3] = out4TextField.getText();
                        inouttimes[0][4] = in5TextField.getText();
                        inouttimes[1][4] = out5TextField.getText();
                        inouttimes[0][5] = in6TextField.getText();
                        inouttimes[1][5] = out6TextField.getText();
                        for (int x = 0; x < 2; ++x)
                             for (int y = 0; y < 2; ++y)
                                  String temp = String.valueOf(inouttimes[x][y]);
                                  if (temp.equals(""))
                                       inouttimes[x][y] = 0;
                                  if (inouttimes[x][y] < 0 && inouttimes[x][y] > 2400)
                                       timeError = true;          
                                       break;
                             if (timeError = true)
                                  break;
                        messageString = temp.getName() + "\n" + temp.getSsn() + "\n" + temp.getTotalPay();
                   JOptionPane.showMessageDialog(null, messageString);
                   }//if (matchBoolean == true)
                   //if SSN match is false then display error message
                   else
                        JOptionPane.showMessageDialog(null, "There is no listing under that Social Security Number.\n" +
                             "Please verify and re-enter.");                    
              }//end if(source == okButton)
              //perform if the Clear button was pressed
              if(source == clearButton)
                   //clear all the textfields
                   dateTextField.setText("");
                   ssnTextField.setText("");
                   in1TextField.setText("");
                   out1TextField.setText("");
                   in2TextField.setText("");
                   out2TextField.setText("");
                   in3TextField.setText("");
                   out3TextField.setText("");
                   in4TextField.setText("");
                   out4TextField.setText("");
                   in5TextField.setText("");
                   out5TextField.setText("");
                   in6TextField.setText("");
                   out6TextField.setText("");
                   sickTextField.setText("");
                   personalTextField.setText("");
                   //set text in field to current date
                   dateTextField.setText(dateString);
         public static void main(String args[])
              //create new entryscreen object called applet
              EntryScreen applet = new EntryScreen();
         //create new frame for applet called window
              Frame window = new Frame("EntryScreen");
         window.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                   //close the applet           
                        System.exit(0);
              //initiate the applet
              applet.init();
    window.add("Center", applet);
    window.pack();
    window.setVisible(true);
    //create entryscreenlayout custom class to position controls on applet screen
    class EntryScreenLayout implements LayoutManager {
    public EntryScreenLayout() {
    public void addLayoutComponent(String name, Component comp) {
    public void removeLayoutComponent(Component comp) {
    public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    Insets insets = parent.getInsets();
    dim.width = 360 + insets.left + insets.right;
    dim.height = 487 + insets.top + insets.bottom;
    return dim;
    public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    return dim;
    public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    Component c;
    c = parent.getComponent(0);
    if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+8,192,24);}
    c = parent.getComponent(1);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+48,152,24);}
    c = parent.getComponent(2);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+48,152,24);}
    c = parent.getComponent(3);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+80,152,24);}
    c = parent.getComponent(4);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+80,152,24);}
    c = parent.getComponent(5);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+112,152,24);}
    c = parent.getComponent(6);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+144,72,24);}
    c = parent.getComponent(7);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+144,72,24);}
    c = parent.getComponent(8);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+176,72,24);}
    c = parent.getComponent(9);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+208,72,24);}
    c = parent.getComponent(10);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+240,72,24);}
    c = parent.getComponent(11);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+272,72,24);}
    c = parent.getComponent(12);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+304,72,24);}
    c = parent.getComponent(13);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+336,72,24);}
    c = parent.getComponent(14);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+176,72,24);}
    c = parent.getComponent(15);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+208,72,24);}
    c = parent.getComponent(16);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+240,72,24);}
    c = parent.getComponent(17);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+272,72,24);}
    c = parent.getComponent(18);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+304,72,24);}
    c = parent.getComponent(19);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+336,72,24);}
    c = parent.getComponent(20);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+368,152,24);}
    c = parent.getComponent(21);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+368,72,24);}
    c = parent.getComponent(22);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+400,72,24);}
    c = parent.getComponent(23);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+400,152,24);}
    c = parent.getComponent(24);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+440,72,24);}
    c = parent.getComponent(25);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+440,72,24);}
    c = parent.getComponent(26);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+176,72,24);}
    c = parent.getComponent(27);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+208,72,24);}
    c = parent.getComponent(28);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+240,72,24);}
    c = parent.getComponent(29);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+272,72,24);}
    c = parent.getComponent(30);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+304,72,24);}
    c = parent.getComponent(31);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+336,72,24);}
    I know it is a lot of code, but I am just starting and couldn't think of an easier way to do this.
    Thank you for any help - it is greatly appreciated. You can email me with any code help - [email protected].
    Steph

    My 2 cents, I dunno what it'll be worth.
    I think you should never convert anything until the final moment that you are at actually getting the int or float number of hours.
    Why are you doing all this Gregorian and conversion gymnastics throughout your calculations?
    To get the current time in milliseconds, use either
    java.util.Date d = new java.util.Date();
    or
    long d = System.currentTimeMillis();
    Use this long number for all your calculations, and only at the end convert it. To convert, you can use java.text.SimpleDateFormat, which I find very straightforward to use. I honestly think you should never convert your dates before doing any calculations, only after doing them, otherwise you'll loose precision and make errors for sure.

  • How use JLabel and JCombobox on one string

    package ReplacementCode;
    import java.awt.BorderLayout;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    class MainFrame extends JFrame {
    private static JTextArea text = new JTextArea(ReadingFromFile.textFromFile.size(), 40);
    private static JScrollPane forText = new JScrollPane(text);
    private static JPanel westPanel = new JPanel();
    private static JPanel forAlphabet = new JPanel();
    private static JPanel forModifyChars = new JPanel();
    private static JLabel[] labels = new JLabel[Alphabet.russianAlphabet.length()];
    private static Object[] massiveOfAlphabet = new Object[Alphabet.russianAlphabet.length()];
    private static JComboBox[] comboBoxes = new JComboBox[Alphabet.russianAlphabet.length()];
    private static JButton startButton = new JButton("!&#1079;&#1072;&#1084;&#1077;&#1085;&#1080;&#1090;&#1100;!");
    private static BoxListener[] boxListeners = new BoxListener[Alphabet.russianAlphabet.length()];
    public MainFrame() {
    super("&#1086;&#1089;&#1085;&#1074;&#1086;&#1074;&#1085;&#1086;&#1077; &#1086;&#1082;&#1085;&#1086;");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    initiasizeCenter();
    initiasizeWest();
    JLabel jlab = new JLabel(Alphabet.russianAlphabet.toUpperCase());
    jlab.setOpaque(true);
    add(forText, BorderLayout.CENTER);
    add(westPanel, BorderLayout.WEST);
    add(startButton, BorderLayout.SOUTH);
    add(jlab, BorderLayout.NORTH);
    setSize(this.getMaximumSize());
    setVisible(true);
    private void initiasizeWest() {
    putAlphabet();
    forModifyChars.setLayout(new BoxLayout(forModifyChars, BoxLayout.Y_AXIS));
    forAlphabet.setLayout(new BoxLayout(forAlphabet, BoxLayout.Y_AXIS));
    for(int ii = 0; ii < Alphabet.russianAlphabet.length(); ii++) {
    comboBoxes[ii] = new JComboBox(massiveOfAlphabet);
    comboBoxes[ii].setSelectedIndex(ii);
    boxListeners[ii] = new BoxListener();
    comboBoxes[ii].addKeyListener(boxListeners[ii]);
    forModifyChars.add(comboBoxes[ii]);
    StringBuffer sb = new StringBuffer();
    sb.append(Alphabet.russianAlphabet.charAt(ii));
    labels[ii] = new JLabel(sb.toString().toUpperCase());
    labels[ii].setOpaque(true);
    labels[ii].setHorizontalTextPosition(JLabel.LEFT);
    labels[ii].setVerticalTextPosition(JLabel.CENTER);
    westPanel.add(forAlphabet);
    westPanel.add(Box.createHorizontalGlue());
    westPanel.add(forModifyChars);
    private static void initiasizeCenter() {
    text.setLineWrap(true);
    for(int ii = 0; ii < ReadingFromFile.textFromFile.size(); ii++)
    text.append(ReadingFromFile.textFromFile.elementAt(ii) + "\n");
    private static void initiasizeSouth() {}
    private static void initiasizeNorth() {}
    private static final void putAlphabet() {
    for(int ii = 0; ii < Alphabet.russianAlphabet.length(); ii++)
    massiveOfAlphabet[ii] = Alphabet.russianAlphabet.charAt(ii);
    private class BoxListener implements KeyListener {
    public BoxListener() {
    public void keyPressed(KeyEvent e) {
    System.out.println("&#1089;&#1083;&#1091;&#1096;&#1072;&#1077;&#1090;&#1083;&#1100; &#1085;&#1072;&#1078;&#1072;&#1090;&#1080;&#1103; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1080; : " + e + "\n");
    public void keyReleased(KeyEvent e) {
    System.out.println("&#1089;&#1083;&#1091;&#1096;&#1072;&#1077;&#1090;&#1083;&#1100; &#1086;&#1090;&#1087;&#1091;&#1089;&#1082;&#1072;&#1085;&#1080;&#1103; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1080; : " + e + "\n");
    public void keyTyped(KeyEvent e) {
    System.out.println("&#1089;&#1083;&#1091;&#1096;&#1072;&#1077;&#1090;&#1083;&#1100; &#1087;&#1077;&#1095;&#1072;&#1090;&#1072;&#1085;&#1080;&#1103; &#1089;&#1080;&#1084;&#1074;&#1086;&#1083;&#1072; : " + e + "\n");
    package ReplacementCode;
    import java.util.Vector;
    abstract class Alphabet {
    final static String russianAlphabet = new String("&#1072;&#1073;&#1074;&#1075;&#1076;&#1077;&#1105;&#1078;&#1079;&#1080;&#1081;&#1082;&#1083;&#1084;&#1085;&#1086;&#1087;&#1088;&#1089;&#1090;&#1091;&#1092;&#1093;&#1094;&#1095;&#1096;&#1097;&#1098;&#1099;&#1100;&#1101;&#1102;&#1103;");
    private static String replacementAlphabet;
    private static double[] ratesOfCharacters = new double[russianAlphabet.length()];
    static Vector<String> replacementedText = new Vector<String>();
    static final void generateAlphabetOfReplacement() {
    boolean[] occupancy = new boolean[russianAlphabet.length()];
    for(int ii = 0; ii < occupancy.length; ii++)
    occupancy[ii] = false;
    char[] ancillaryMassiveOfCharacters = new char[russianAlphabet.length()];
    for(int ii = 0; ii < ancillaryMassiveOfCharacters.length; ii++) {
    for(;;) {
    int ancillaryPositionOfCharacter = (int) (Math.random() * ancillaryMassiveOfCharacters.length);
    if(occupancy[ancillaryPositionOfCharacter] == false) {
    occupancy[ancillaryPositionOfCharacter] = true;
    ancillaryMassiveOfCharacters[ii] = russianAlphabet.charAt(ancillaryPositionOfCharacter);
    break;
    replacementAlphabet = new String(ancillaryMassiveOfCharacters);
    static final void workWithText(Vector<String> unreplacementText) {
    generateAlphabetOfReplacement();
    nullingOfRates();
    replacementedText.removeAllElements();
    for(int ii = 0; ii < unreplacementText.size(); ii++) {
    char[] occupancyMassive = unreplacementText.elementAt(ii).toCharArray();
    for(int jj = 0; jj < occupancyMassive.length; jj++) {
    //verification of agreement of character's in text with basic alphabet
    for(int kk = 0; kk < russianAlphabet.length(); kk++) {
    if(Character.isUpperCase(unreplacementText.elementAt(ii).charAt(jj)) &&
    occupancyMassive[jj] == Character.toUpperCase(russianAlphabet.charAt(kk))) {
    occupancyMassive[jj] = Character.toUpperCase(replacementAlphabet.charAt(kk));
    ratesOfCharacters[kk]++;
    break;
    if(Character.isLowerCase(unreplacementText.elementAt(ii).charAt(jj)) &&
    occupancyMassive[jj] == russianAlphabet.charAt(kk)) {
    occupancyMassive[jj] = replacementAlphabet.charAt(kk);
    ratesOfCharacters[kk]++;
    break;
    //save new replacemented text
    replacementedText.add(new String(occupancyMassive));
    //            System.out.println(unreplacementText.elementAt(ii));
    //            System.out.println(replacementedText.elementAt(ii));
    static final void workWithText(Vector<String> unreplacementText, String oldAlphabet, String newAlphabet) {
    nullingOfRates();
    replacementedText.removeAllElements();
    for(int ii = 0; ii < unreplacementText.size(); ii++) {
    char[] occupancyMassive = unreplacementText.elementAt(ii).toCharArray();
    for(int jj = 0; jj < occupancyMassive.length; jj++) {
    //verification of agreement of character's in text with basic alphabet
    for(int kk = 0; kk < oldAlphabet.length(); kk++) {
    if(Character.isUpperCase(unreplacementText.elementAt(ii).charAt(jj)) &&
    occupancyMassive[jj] == Character.toUpperCase(oldAlphabet.charAt(kk))) {
    occupancyMassive[jj] = Character.toUpperCase(newAlphabet.charAt(kk));
    ratesOfCharacters[kk]++;
    break;
    if(Character.isLowerCase(unreplacementText.elementAt(ii).charAt(jj)) &&
    occupancyMassive[jj] == oldAlphabet.charAt(kk)) {
    occupancyMassive[jj] = newAlphabet.charAt(kk);
    ratesOfCharacters[kk]++;
    break;
    //save new replacemented text
    replacementedText.add(new String(occupancyMassive));
    //            System.out.println(unreplacementText.elementAt(ii));
    //            System.out.println(replacementedText.elementAt(ii));
    private static void nullingOfRates() {
    for(int ii = 0; ii < ratesOfCharacters.length; ii++)
    ratesOfCharacters[ii] = 0;
    }the problem is in westPanel; how we can typed text from the Jlabel near JCombobox
    now - text from combobox we can see, and text from label - don't.
    and one of condition is don't crash massive of JCombobox and Jlabel
    please help me

    if if was different mod then only create many vertical Jpanels, with pair jlabel, jcombobox, please write...i don't want to do this because it wil bee many references on Jpanels-> many memory..

Maybe you are looking for

  • Adobe Reader Version 9.1.1 - Unable to close Adobe Reader.

    Using Firefox Version 3.0.10, under Microsoft Windows Vista Home Premium Edition 32-bit, patched as of today. I open a pdf file, Adobe Reader opens a new window, I can read/print pdf file. I select "Close" (Red X in upper right hand corner.) nothing

  • InDesign CS3 - Default Black color issue

    Default Black color converted as Spot color in Indesign CS3. I'm using default color "Black" in InDesign CS3. While creating PS from InDesign CS3 and convert it as PDF using Distiller 7 & 8, it would have changed as "Spot Color Black" instead of colo

  • IPhoto 6 slideshows not full screen!!!

    First of all, as this problem has not changed since iPhoto 5.02 on OS X 10.3.9, let me provide you with some background... http://discussions.apple.com/thread.jspa?messageID=1425902&#1425902 Now, let me detail the problem again. I have a Mac Mini 1.2

  • Deployment failed. Building failed

    Hi am using netbean 6 ,glassfish v2 and sun java application server 9 When am try to run my jsp file am getting Deployment error report with further error given below. Deployment error: The Sun Java System Application Server could not start. More inf

  • X-FI xtrememusic drivers not loading problem - having to reinstall drivers every other reb

    I am having a bizarre problem with my xtrememusic card. Latest drivers and all, the motherboard is a gigabyte GA-965P-DQ6 (rev .0). Basically, I install the drivers and reboot, the card works fine. I reboot, it stops working, gives me a "can't load d