Need help on drawing multiple squares on the screen

I am working on a project for aircraft seating and what i have to do is create square on the screen as seat. I got to draw 180 squares on the screen and it sounds easy but i have been stuck at it for about 10 days now my superviser doesn't know java so he can't help me on what i should do next and java superviser's told me they have no time to see me so if anyone here can help to guide me where i am goin wrong or how i should do it would be very helpful. Here is the code i have so far i think i am maybe close to gettin it working but then again i could be far off.
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Seating extends JFrame {
    private JPanel boardPanel;
    private JPanel panel2;
    private Square board[][];
    public Seating() {
        boardPanel = new JPanel();
        boardPanel.setLayout(new GridLayout(6,30,0,0));
        //create board
        board = new Square[6][30];
        //rows in the board
       for(int row = 0; row < board.length; row++)
           //column on the board
            for(int column = 0; column < board[row].length; column++)
                //create square
                board[row][column] = new Square(' ', 3 * row + column);
                //add square
                boardPanel.add(board[row][column]);
            panel2 = new JPanel();
            panel2.add(boardPanel, BorderLayout.CENTER);
            add(panel2, BorderLayout.CENTER);
            setSize(2000,1500);
            setVisible(true);
             private class Square extends JPanel
                public Dimension getPreferedSize()
                  return new Dimension(20,20);
                public Dimension getMinimumSize()
                    return getPreferedSize();
                public void paintComponent(Graphics g)
                    super.paintComponents(g);
                    g.drawRect(0, 0, 19, 19);
}

Yeah I'd make a Seat class, subclassing JLabel, and then add some business logic to them to reflect that. For example, if they're already booked, given them a different color and disable clicks on them. If they're bookable, add a mouse click listener. Maybe I'd make different subclasses of Seat for those different roles. I'd add them all to the grid, but also add them to a Map indexed by seat name or something so I could find them and update them as needed.

Similar Messages

  • Need help to draw a graph from the output I get with my program please

    Hi all,
    I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
    on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
    My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
    Please help me.
    The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
    The initial deposit made was: 200.0
    After year: 1        Amount is:  210.00
    After year: 2        Amount is:  220.50
    After year: 3        Amount is:  231.53
    After year: 4        Amount is:  243.10
    After year: 5        Amount is:  255.26
    After year: 6        Amount is:  268.02
    After year: 7        Amount is:  281.42
    After year: 8        Amount is:  295.49
    After year: 9        Amount is:  310.27
    After year: 10        Amount is:  325.78
    After year: 11        Amount is:  342.07
    After year: 12        Amount is:  359.17
    After year: 13        Amount is:  377.13
    After year: 14        Amount is:  395.99
    After year: 15        Amount is:  415.79
    After year: 16        Amount is:  436.57
    After year: 17        Amount is:  458.40And here is my code that Iv'e done so far:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Math;
    import java.text.DecimalFormat;
    public class CompoundInterestProgram extends JFrame implements ActionListener {
        JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
        JTextField amountText = new JTextField(5);
        JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
        JTextField yearstext = new JTextField(5);
        JButton drawButton = new JButton("Draw Graph");
        public CompoundInterestProgram() {
            super("Compound Interest Program");
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            amountText.addActionListener(this);
            yearstext.addActionListener(this);
            JPanel panel = new JPanel();
            panel.setBackground(Color.white);
            panel.add(amountLabel);
            amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
            panel.add(amountText);
            panel.add(yearsLabel);
            yearsLabel.setToolTipText("Range of years must be 1 - 25!");
            panel.add(yearstext);
            panel.add(drawButton);
            add(panel);
            setVisible(true);
            public static void main(String[] args) {
                 DecimalFormat dec2 = new DecimalFormat( "0.00" );
                CompoundInterestProgram cip1 = new CompoundInterestProgram();
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new GraphPanel());
                f.setSize(500, 500);
                f.setLocation(200,200);
                f.setVisible(true);
                Account a = new Account(200);
                System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
                for (int year = 1; year <= 17; year++) {
                      System.out.println("After year: " + year + "   \t" + "Amount is:  " + dec2.format(a.getBalance() + a.calcInterest(year)));
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    class Account {
        double balance = 0;
        double interest = 0.05;
        public Account() {
             balance = 0;
             interest = 0.05;
        public Account(int deposit) {
             balance = deposit;
             interest = 0.05;
        public double calcInterest(int year) {
               return  balance * Math.pow((1 + interest), year) - balance;
        public double getBalance() {
              return balance;
    class GraphPanel extends JPanel {
        public GraphPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.red);
    }Your help would be much appreciated.
    Thanks in advance.

    watertownjordan wrote:
    http://www.jgraph.com/jgraph.html
    The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
    The best free charting library that I know of is JFreeChart from www.jfree.org.

  • Need help everytime i try to facetime the screen is black

    My boyfreind and i are having problems with our facetime the screen is black on both ends can hear each other but the only thing we see is ourselves in the corner

    Have you tried a Reset of both Devices...
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430
    Troubleshooting FaceTime
    http://support.apple.com/kb/TS3367

  • Need help Setting up Multiple Static Ip , 1 for each port of the fios router

    Need help Setting up multiple Static Ip on my fios router
    I have been trying to figure out how to set up multiple ip in my fios router.
    However I kind of managed how to set up multiple static ip However the way I want it is for each port of my router to have an external ip signed to it. ( like 4 different modem in 1 )
    Verizon gave me 5 static ip but they can not help me how to set it up.
    Have anyone here done more then one static ip on different ports? I assume that the process will be the after the second static ip.

    You want to set up Static Nat. You will not assign the IP to a port, but rather to a local machine. Figure out what machines you want your IP's to go to. Under the firewall section you will see static nat. Pick the machine you want and enter one of the IP's you were assigned.

  • Need help in creating multiple signature forms?

    need help in creating multiple signature forms that can be digitally signed in adobe reader

    Automator gets a bit unweildy when trying to vary things outside of what the actions provide.  Since you are already using an AppeScript in your workflow, might as well do the whole thing:
    set baseFolder to (path to desktop) -- the location to create the folder
    display dialog "Please provide a new folder name:" default answer "test"
    set folderName to text returned of the result
    repeat -- keep repeating until a number is returned
      display dialog "How many subfolders?" default answer "5"
      set theNumber to text returned of the result
        try -- test the result
          set theNumber to theNumber as integer
          exit repeat -- success
        end try
    end repeat
    tell application "Finder"
      try -- make new folder
        set newFolder to (make new folder at baseFolder with properties {name:folderName})
      on error number -48 -- skip errors if the folder is already there
        set newFolder to ((baseFolder as text) & folderName) as alias
      end try
      repeat with X from 1 to theNumber
        try -- make new subfolder
          make new folder at newFolder with properties {name:folderName & X}
        on error number -48 -- skip errors if the folder is already there
        end try
      end repeat
    end tell

  • I need help, yesterday I installed and reinstalled the Yosemite system and take long to turn on my laptop, the bar takes to fill, and I'm worried. Can you help? thank

    I need help, yesterday I installed and reinstalled the Yosemite system and take long to turn on my laptop, the bar takes to fill, and I'm worried.
    Can you help? thank

    revert back to Maverick that is what I had to finally do. This was the worst upgrade I have ever seen. Hopefully you have Time Machine backup and can revert back. It was pretty painless except for a few issues. I will wait until Apple gets their stuff together on this upgrade or may never will.

  • Hi i need help one of my key on the keyboard dosen't work for some reason please help

    hi i need help one of my key on the keyboard dosen't work for some reason please help

    try smc reset
    http://support.apple.com/kb/ht3964
    and Pram reset
    http://support.apple.com/kb/ht1379
    (Try pram a few times to get correct sequence)
    Check what you have selected in
    system preferences/system/accessibility/keyboard
    and system preferences/hardware/keyboard  (keyboard and keyboard short cuts tabs)

  • I need help writing a script that finds the first instance of a paragraph style and then changes it

    I need help writing a script that finds the first instance of a paragraph style and then changes it to another paragraph style.  I don't necessarily need someone to write the whole thing, by biggest problem is figuring how to find just the first instance of the paragraph style.  Any help would be greatly appreciated, thanks!

    Hi,
    Do you mean first instance of the paragraph style
    - in a chosen story;
    - on some chosen page in every text frames, looking from its top to the bottom;
    - in a entire document, looking from its beginning to the end, including hidden layers, master pages, footnotes etc...?
    If story...
    You could set app.findTextPreferences.appliedParagraphStyle to your "Style".
    Story.findText() gives an array of matches. 1st array's element is a 1st occurence.
    so:
    Story.findText()[0].appliedParagraphStyle = Style_1;
    //==> this will change a paraStyle of 1st occurence of story to "Style_1".
    If other cases...
    You would need to be more accurate.
    rgds

  • Draw a square with the cursor

    i would like to draw a square with the movement of the coursor, while its left button is clicked and the cursor is over an image.
    when i leave of pushing the right button the square have to dissapear.
    if you don't understand, it's the same in windows when you click the left button and square appears.
    My question is how can i do this?
    thanks

    Not sure I completely understand the question, but maybe this will give you an idea:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DrawSquare extends JPanel
         Point startPoint = null;
         Point endPoint = null;
         public DrawSquare()
              setPreferredSize(new Dimension(500,500));
              MyMouseListener ml = new MyMouseListener();
              addMouseListener(ml);
              addMouseMotionListener(ml);
              setBackground(Color.white);
         public void paintComponent(Graphics g)
              // automatically called when repaint
              super.paintComponent(g);
              g.setColor(Color.black);
              if (startPoint != null && endPoint != null)
                   // draw the current dragged line
                   int x = Math.min(startPoint.x, endPoint.x);
                   int y = Math.min(startPoint.y, endPoint.y);
                   int width = Math.abs(endPoint.x - startPoint.x);
                   int height = Math.abs(endPoint.y - startPoint.y);
                   g.drawRect(x, y, width, height);
         class MyMouseListener extends MouseInputAdapter
              public void mousePressed(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        startPoint = e.getPoint();
                        repaint();
              public void mouseReleased(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        startPoint = null;
                        endPoint = null;
    //                    repaint();
              public void mouseDragged(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        endPoint = e.getPoint();
                        repaint();
         public static void main(String[] args)
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              DrawSquare d = new DrawSquare();
              frame.getContentPane().add( d );
              frame.pack();
              frame.setVisible(true);
    }

  • New airport user need help setting up a pc on the network

    went and bought a airport extream today and my mac works fine on it but i also have a pc and need help getting it to work with the airport express. it seems to see the airport in the network slection screen but after i put in the pass i get nothing and it returns to the "chose a wireless network" can anyone help?

    Thanks for the reply.
    That's interesting, I guess I had assumed that would be a basic thing.
    Right now the 4000 number is in port 1, and then 4244 is in port 2. So if no one else is on the phone, and my  boss picks up his phone, dials 9 then XXX-XXXX, he will be routed outbound on the 4000 line on port 1. Then while he's talking, if I pick up the phone and dial 9 then XXX-XXXX, I will be routed out on the 4244 line on port 2.
    Am I understanding that correctly?
    If that is the case, then that is a bit frustrating. Our 4000 line has everything on it, call waiting, caller id, long distance, etc. But the 4244 line is just a basic service. So if I'm calling local or toll free, I don't want to tie the other line up in case someone else needs to make a long distance call to a client. Is there any work around to that at all? Is there any way to use steering digits to point the call to the right line? Would we have to put the PSTN lines on seperate SPA400's?
    Again, any comments and suggestions are much appreciated!
    Message Edited by VoIP_Me on 07-30-2008 06:27 AM
    Message Edited by VoIP_Me on 07-30-2008 06:28 AM

  • I NEED HELP!! Been calling since the end of Nov and being charged for a Warranty device. The device was returned the next day!! Been calling twice a week.. NEED RESOLUTION

    I NEED HELP!! Been calling since the end of Nov and being charged for a Warranty device. The device was returned the next day!! Been calling twice a week.. I NEED HELP 6 TCC TICKETS HAVE BEEN OPENED - PROMISED CALLS BACK AND NEVER GET CALLS.
    About to cancel my account and move to AT&T
    TCC TICKETS:  (removed)
    I am trying here for the last resort. After this evening my account along with my business account will be cancelled. Total lines that Verizon will have lost will be 93 lines.
    PLEASE SOMEONE JUST HELP ME!!!!
    I already tweeted and facebook messaged Verizon. Your CS group has gone down hill over the last 3-6 months. I use to enjoy being a customer.
    >> Edited to comply with the Verizon Wireless Terms of Service <<

    not all the lines have ETF's. I have 30 tablets and the rest phones. The phones have ETFs and the tablets are all month to month.
    The total to move my account over is going to come out to about $8500.
    Rep has been trying to get my business for years.  I was always loyal to Verizon until this happened.

  • Macbook pro 2006 can only start on safe mode and it has a lot of squares on the screen

    My macbook pro 2006 can only start on safe mode and it has a lot of squares on the screen even if I use an external display help? heres a picture http://i61.tinypic.com/vebszt.jpg

    Mespinal130,
    have you tried running your MacBook Pro’s Apple Hardware Test, to see if it can detect anything amiss?

  • Drawing without realizing on the screen

    Can you draw a component onto a BufferedImage object without ever drawing that object onto the screen?
    I've got the following code.
    JLabel jl = new JLabel("Test Label");
    jl.setSize(jl.getPreferredSize());
    BufferedImage bi = new BufferedImage();
    Graphics g = bi.getGraphics();
    jl.paintAll(jl);
    the image has nothing painted onto it. Do I need to call a specific function before asking the component to display itself? OR do I have to add it to a jPanel first? Anyone else have this problem?
    Thanks in advance

    This is the code:
    JLabel jl = new JLabel("Test Label");
    jl.setSize(jl.getPreferredSize());
    java.awt.image.BufferedImage bi =
    new java.awt.image.BufferedImage(100, 100, java.awt.image.BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    jl.paint(g);
    // I see the final result adding a label with the
    // BufferedImage just filled.
    getContentPane().add(new JLabel(new ImageIcon(bi)));
    setVisible(true);
    validate();

  • My ipad has a message that i cloud needs to be backed up . but now the screen is frozen

    my ipad has a message that icloud needs to be backed up. but now the screen is frozen

    Try a reset:
    Hold the Sleep and Home button down until you see the Apple logo.

  • My second hand ipad, recently bought from ebay, surfs the internet but a large black square locks the screen if you try to access any APP or apple product. MY apple ID seems fine, i re-set my password a few days ago and joined icloud etc. What can i do?

    Hello all. My secondhand ipad, recently bought from ebay, surfs the internet fine but a large black square locks the screen if I try to access any APP. What is the problem and what can i do about it please?

    Hello all. My secondhand ipad, recently bought from ebay, surfs the internet fine but a large black square locks the screen if I try to access any APP. What is the problem and what can i do about it please?

Maybe you are looking for

  • Failed to set security on SQL Server registry key. Error: 2

    Hi, I have a Primary site (mixed mode) running SCCM 2007 SP1 for many months now with no issues. This site is made up of two Win 2008 sp2 servers sharing the SCCM roles:- SCCM01 - Site server, DP, RP, PXE and SQL2005 hosting the SCCM database SCCM02

  • Load Image into JApplet

    Hello to all Java expect coder, i would like to load an image to an applet but after it flash once time then it just disappear. Below is my code : * SodaVendingMachineApplet.java * Created on June 8, 2008, 4:08 PM import java.awt.*; import java.awt.i

  • How to enable broadcast agent manager (GENERALBA) account

    Post Author: jrodrig1 CA Forum: Authentication Hi, I have managed to disable the broadcast agent manager (GENERALBA) account by typing the whrong password three times. I have gone to Supervisor as BOADMIN (General supervisor) but I cannot see GENERAL

  • Just bought a mac desktop and how do sync my apps to it from iPad?

    Just bought a mac desktop and how do sync my apps to it from iPad?

  • Do you have suggestions for naming conventions within AIF?

    Hi Folks! Being new to AIF I'm currently in the information gathering phase for myself and colleagues as we are starting to think about implementing interfaces with the help of this toolbox. I already found and read (or at least skimmed!) through var