Swing code help

Guys,
Thanks first of all to those of you who have been a great help over the past few days. I have one last problem that i'm not sure how to tackle.
I'm doing a theatre booking system which has a GUI. My main screen is using a card layout.
I have a theatre class, a booking class, performance and seating classes. I want to implement code for making a booking which will display a graphical representation of the seats for a particular section of the theatre. My seating is divided into stalls, royal circle, upper circle etc. Each of these blocks of seating has x rows and y columns.
I want to show on a panel all seats. Booked ones coloured red, free ones coloured green - or some other approach which would be just as effective. I want to click a seat or several seats to book them for one customer.
What approach is best for this problem? How should I draw the seats? Line drawings? Components? Suggestions on how to tackle this problem please.
Many thanks.

How bout this:
Create your own subclas of Shape (sub class Rectangle if you just want your seats as rectangles or if they need to be a more complicated shape use Polygon) but add your own field colour (of type Color!, defaulted to green) which has a getter and a setter method for colour (or just setred, setgreen methods) and just one constuctor which takes a location. size and colour are set by default in the constructor. Iterate over your x and y axis creating these and storing them in an array, something line:
int xmax = 5;
int ymax = 3;
int gap = 5;
Seat[] seats = new Seat[xmax * ymax]; //Where seat is you Shape (also array should be class level)
int count = 0;
for (int  x = 0; x < xmax; x++){
   for (int y = 0; y < ymax; y++){
       seats[count] = new Seat( gap * x, gap * y); //Obviously this would be alot more complicated if you use Polygon as all points would need offsetting by x, y.
}then in your draw method:
for (allseats using i) {
     Seat seat = seats;
g2.setColor(seat.getColour());
g2.draw(seat)
Add a mouselistener to the component you are drawing on which checks if a seat was clicked on:
mouseClicked(MouseEvent me {
for (allseats using i) {
     Seat seat = seats;
if (seat.contains(me.getPoint()) {
seat.setColour(Color.RED);
//And anything else you want to do
repaint();
None of this is very thought through and all just typed straight into reply box so probably loads of little mistakes and improvements but somewhere to start from perhaps.
Hope this helps,
Alex.

Similar Messages

  • Survey creation abap code help needed

    hello experts,
    I need to create a survey in crm, by taking values from end-user from a webpage
    A sample code help is needed.
    Thanks in advance

    Take a look at this SAP note - It does a pretty good job of detailing the steps for you.  No coding necessary, it worked out of the box for us after patching this note.
    https://service.sap.com/sap/support/notes/638320

  • Messy Swing code

    Hello there,
    I'm a uni student and since starting learning java, we have always had it drilled into us about creating neat code which is nicely commented and has methods small enough to fit into one page (so you don't have to scroll up and down when looking at one method). Now I am learning Swing and it seems like a waste of effort to keep my methods really short. My question is regarding the 'best practice' when writing Swing code, does it really matter if I have a method createJMenuBar() which is 15 times taller than my screen or should I break it up into methods - one method per JMenuItem? It seems daft but I thought I'd ask.
    Thanks
    Jack
    Edited by: jackCharlez on Nov 20, 2009 4:56 PM

    does it really matter if I have a method createJMenuBar() which is 15 times taller than my screenWell, in my editor I can display about 50 lines of code per screen. So that would be about 750 lines of code which sounds a bit excessive to me. Many classes aren't even that big.
    I can't possibly think why your menubar would take that many lines of code. But an easy way to break it up would be to have a method for creating each menu, which I think is better than one method per menu item.

  • Inquiring minds may find this error code helpful: 0x207

    Hopefully I'm asking this in the right forum. I just downloaded the update for Microsoft Remote Desktop for Windows Phone 8.1 (I am actually running Denim on a 1520 but that may not matter). The version is 8.1.8.13 released 3/4/2015. I am trying to connect
    to a RemoteApp application but I am receiving the following error message shortly after it tries the redirection process (I think it fails at the securing remote connection part after it attemps the redirction to the RemoteApp application collection server):
    Connection error
    We couldn't connect to the remote PC. This might be due to an expired password. If this keeps happening, ask your admin or tech support for help.
    Inquiring minds may find this error code helpful: 0x207
    I am able to connect directly to both the broker server as well as the RemoteApp collection server with this application with the same credentials and am only experiencing this when trying to connect to a RemoteApp application.
    We are running Server 2012 R2 for both the broker/web and the collection servers. We are not using a gateway server as we use an SSL VPN concentrator instead for access outside of our network. We have server farms set up as well in the RemoteApp topology.
    Any info would help or let me know if I'm not posting in the right forum for this issue. I know this is a very recent release so I'm trying to figure out if I should wait for a bug fix or if there's something that I can do on my end.
    Thank you in advance for your time!

    Hi Scott,
    Please check your configuration once again and the certificate must be well configured. Also for accessing RemoteApp there might be the permission issue for your use, recheck once and verify. You can also got through
    this article for information.
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Redemption code help that you keep sending everyone to is NOT HELPING. It just tells you to put in the redemption code. IF I HAD THE CODE I WOULD HAVE PUT IT IN!! How do I find the code?

    Redemption code help that you keep sending everyone to is NOT HELPING. It just tells you to put in the redemption code. IF I HAD THE CODE I WOULD HAVE PUT IT IN!! How do I find the code?

    Version 5.5 was/is not part of the Cloud, so you could not have subscribed to that version
    You install version 5.5 on a 2nd computer exactly the same way you did the 1st time... put the disc in the drive and enter your serial number when asked
    Does your serial number show on your account page?
    https://www.adobe.com/account.html for serial numbers on your Adobe page... or
    Lost serial # http://helpx.adobe.com/x-productkb/global/find-serial-number.html

  • Code help in writing  report Program

    Hello experts
    I have to write a selection screen program based on the following requirements (only for sales Org:5090, plant:9000, Outbound delivery type= "LF")
    Selection parameters:
    Material (lips-matnr)
    Sold to party(likp-kunag): can hardcode it to 5090
    Sales Org(likp-vkorg)
    Plant(lips-werks) : hard code it to plant:9000
    Sales order(likp-vbeln)
    Actual goods movement dates(likp-wadat_ist)
    Invoice number
    Sales order
    Output
    material numberlips~matnr ( should Display only S* materials  and  material type FERT)
      Serial number of the device shipped (objk-sernr)
    Delivery number (lips~vbeln)
    Invoice number (vbrp-vbeln)
    Invoice price=Vbrp-vbeln/quantity (invoice price)
      Notification number (Viqmel-QMNUm)
      KBB Repair Level(VIQMEL-QMTXT from QMCOD ) 
      KBC Repair level(VIQMMA-MNCOD from KBC-SM07 code group(VIQMMA-MNGRP))
    code help is higly appreciated,
    Thanks
    Sp

    Hi anurag,
    Code is going like this, i could able to display it but when i run it ABAP Dump is coming.
    what could be the reason?
    Tahnks
    SP
    *& Report  ZSDR_PRICING_KSE_RPT                                        *
    REPORT  ZSDR_PRICING_KSE_RPT          .
    TABLES: likp, lips, vbfa, vbak.
    TYPE-POOLS: slis.
    */ Selection and Input Parameters
    SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-003.
    SELECT-OPTIONS: s_matnr FOR lips-matnr,
                    s_kunag FOR likp-kunag.
    SELECT-OPTIONS: s_vkorg FOR likp-vkorg NO INTERVALS,
                    s_werks FOR lips-werks.
    SELECT-OPTIONS: s_vbeln FOR likp-vbeln,
                    s_waist FOR likp-wadat_ist.
    SELECT-OPTIONS: s_vgbel FOR lips-vgbel.
    SELECTION-SCREEN END OF BLOCK block2.
    DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
    TYPES: BEGIN OF ty_data,
           matnr TYPE lips-matnr,
           sernr TYPE equi-sernr,
           vbeln TYPE lips-vbeln,
           invno TYPE vbfa-vbeln,
           qmnum TYPE vbak-qmnum,
           netwr type vbrp-netwr,
           END OF ty_data.
    DATA: gt_data TYPE TABLE OF ty_data WITH HEADER LINE.
    TYPES: BEGIN OF ty_lips,
           vbeln TYPE likp-vbeln,
           matnr TYPE lips-matnr,
           wersk TYPE lips-werks,
           vgbel TYPE lips-vgbel,
           END OF ty_lips.
    DATA: gt_lips TYPE TABLE OF ty_lips WITH HEADER LINE.
    DATA: gt_vbfa TYPE TABLE OF vbfa WITH HEADER LINE.
    DATA: gt_vbrp TYPE TABLE OF vbrp WITH HEADER LINE.
    TYPES: BEGIN OF ty_ser01,
           lief_nr TYPE ser01-lief_nr,
           obknr TYPE ser01-obknr,
           sernr TYPE objk-obknr,
           END OF ty_ser01.
    DATA: gt_ser01 TYPE TABLE OF ty_ser01 WITH HEADER LINE.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM display_data.
    *& Form get_data
    FORM get_data.
      SELECT likpvbeln lipsmatnr lipswerks lipsvgbel
             INTO CORRESPONDING FIELDS OF TABLE gt_lips
             FROM likp INNER JOIN lips ON lipsvbeln = likpvbeln
             WHERE lips~matnr IN s_matnr
             AND lips~werks IN s_werks
             AND likp~kunag IN s_kunag
             AND likp~wadat_ist IN s_waist
             AND lips~vgbel IN s_vgbel
             AND likp~vkorg IN s_vkorg.
      IF NOT gt_lips[] IS INITIAL.
        SELECT vbeln vbelv INTO CORRESPONDING FIELDS OF TABLE gt_vbfa
        FROM vbfa
        FOR ALL ENTRIES IN gt_lips
          WHERE vbelv = gt_lips-vgbel
          AND vbtyp_n = 'M'.
        IF NOT gt_vbfa[] IS INITIAL.
          SELECT vbeln matnr netwr
          INTO CORRESPONDING FIELDS OF TABLE gt_vbrp
          FROM vbrp FOR ALL ENTRIES IN gt_vbfa
          WHERE vbeln = gt_vbfa-vbeln.
          SELECT ser01lief_nr ser01obknr objk~sernr
          INTO CORRESPONDING FIELDS OF TABLE gt_ser01
          FROM ser01 INNER JOIN objk ON objkobknr = ser01obknr
          FOR ALL entries IN gt_vbfa
          WHERE ser01~lief_nr = gt_vbfa-vbeln
          AND taser EQ 'SER01'.
        ENDIF.
      ENDIF.
      clear: gt_data[].
      LOOP AT gt_lips.
        LOOP AT gt_vbfa WHERE vbelv = gt_lips-vgbel.
          READ TABLE gt_vbrp WITH KEY vbeln = gt_vbfa-vbeln
          matnr = gt_lips-matnr.
          LOOP AT gt_ser01 WHERE lief_nr = gt_vbfa-vbeln.
            gt_data-matnr = gt_lips-matnr.
            gt_data-sernr = gt_ser01-sernr.
            gt_data-vbeln = gt_lips-vbeln.
            gt_data-invno = gt_vbfa-vbeln.
            gt_data-netwr = gt_vbrp-netwr.
            APPEND gt_data.
          ENDLOOP.
        ENDLOOP.
      ENDLOOP.
    ENDFORM. " get_data
    *& Form display_data
    FORM display_data.
      DATA: lv_repid TYPE sy-repid.
      lv_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
      EXPORTING
      i_program_name = lv_repid
    I_INTERNAL_TABNAME =
      i_structure_name = gt_data
    I_CLIENT_NEVER_DISPLAY = 'X'
    I_INCLNAME =
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE =
      CHANGING
      ct_fieldcat = gt_fieldcat
    EXCEPTIONS
    INCONSISTENT_INTERFACE = 1
    PROGRAM_ERROR = 2
    OTHERS = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    i_callback_program = lv_repid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    I_STRUCTURE_NAME =
    IS_LAYOUT =
    it_fieldcat = gt_fieldcat
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    IT_EVENTS =
    IT_EVENT_EXIT =
    IS_PRINT =
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    t_outtab = gt_data
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.

  • I was messing around with my iPad and put in a in app purchese and forgot the pass code help!

    I was messing around with my iPad and put in a in app purchese and forgot the pass code help!

    Do you mean you forgot the passcode for your iPad?  If so you need to restore it through the recovery mode described in http://support.apple.com/kb/HT1808

  • Redemption Code Help, where do I locate it?

    Redemption Code Help, where do I locate it?

    You have activate the subscription only once in the month of August 2014, so you can activate it one more time, if the Cc is asking for serial number then please follow the steps:
    Creative cloud do not need a serial number. it will be using your Adobe ID on which you have purchased the creative cloud membership.
    So you need to login with your Adobe ID and password to activate the cloud membership.
    Log out & log back in of the CC Desktop App.
    In case it is not signing in successfully please try the following:
    I don't know which operating system you are working on so i am giving you some steps windows and MAC OS:
       Windows:
       In windows 7 navigate to following location:
         /windows/system32/drivers/etc
       1. look out for "Hosts" file
       2. Open it with notepad
       3. Check if you have any entry for Adobe
       4. Remove the entries and try again launching any product from CC
       On Windows XP navigate to following location:
       \windows\system32\drivers\etc
       1. look out for "Hosts" file
       2. Open it with notepad
       3. Check if you have any entry for Adobe
       4. Remove the entries and try again launching any product from CC
       Mac:
       1. Please click on "Go" and navigate to /private/etc
       2. Open "hosts" file and check out for any entries for Adobe.com
       3. Remove the entries and save the file
       4.  try again launching any product from CC
    You can refer :
    http://helpx.adobe.com/creative-cloud/kb/ccm-prompt-serial-number.html
    http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-i ssues.html.
    Please let us know if it worked.
    Regards,
    Rajshree

  • HT201209 When I try to redeem it says error invalid code help me please.

    When I try to redeem it says error invalid code help me please.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact
    Note: iTunes Gift Cards are only Valid in Country of issue

  • I just had to buy a new computer because my "vintage" Mac died. after migrating my backup drive over my Adobe creative suite no longer wroks I get a 150:30 error code HELP!

    I just had to buy a new computer because my "vintage" Mac died. After migrating my backup drive over to my New mac book my Adobe CS no longer works. I get a 150:30 error code HELP!

    You need to reinstall it properly, not use migration.
    Mylenium

  • I need help, I have alot of questions too (swing, code, optimizing...)

    Hi, I'm having a little trouble with aligning my GUI correctly. Here are screenshots from my laptop which runs OS 10.4 & my PC running Windows 2000:
    http://kavon89.googlepages.com/clipper.png <= On the laptop
    http://kavon89.googlepages.com/clipper_windows2000.jpg <= On the PC
    I don't know why the OS 10.4 looks almost perfect and the win 2k is a disaster. I played with it on my laptop and once i came over to my PC to post a problem about somthing else, i noticed this issue on my windows box. My guess is that either the JButton on OS 10.4 is smaller than the one for win2k and causing the automatic organizing to malfunction... or maybe the pixels are larger on my PC then on my laptop.
    I was thinking that I should make diffrent .jar's for each OS since there are GUI issues.... or is there a way to make it universal? (i read somwhere about GridBag?)
    Next off, Is there any way to reduce the size of the space between the JList box closest to the top of the frame & the buttons & text box below it? I tried all sorts of resizing and it seems stuck on some sort of space there which i would like to make compact.
    Those are all the swing questions i have ^
    About my code:
    I recently added 2 buttons which are at the bottom of the OS 10.4 screenshot, Clear Box & Drop All. Clear Box is the one I made work, or so I thuoght. I wrote this for my Clear Box button (by the way, the button is sapose to just clear the text box directly to the upper left of itself.)
           if(e.getSource() == buttonc)
               textfield.setText("");
           }I thought that was the best way to go about clearing the text box. just setting it to blank. But after some testing to ensure there were no reprocussions, I found a problem... When i select somthing from my JList and hit Clear Box, it deletes the entry in the JList when it is not sapose to. It also does it when there is text in the textbox and i have selected somthing in my JList. I haven't been able to figure out why. Here is my full source code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class winclipstart
      JButton buttona, buttond, buttonc, buttonda;
      DefaultListModel clippedtxt = new DefaultListModel();
      JTextArea textfield;
      JList ClippedLines;
      public static void main(String[] cheese){new winclipstart().buildGUI();}
      public void buildGUI()
        JFrame frame;
        Container contentPane;
        JPanel Bottom = new JPanel();
        JPanel Top = new JPanel();
        frame = new JFrame();
        frame.setTitle("Clipper 0.1 Beta");
        contentPane = frame.getContentPane();
        ClippedLines = new JList(clippedtxt);
        JScrollPane scroll2 = new JScrollPane(ClippedLines, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll2.setPreferredSize(new Dimension(400,150));
        textfield = new JTextArea(3,20);
        JScrollPane scroll1 = new JScrollPane(textfield, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        buttona = new JButton("Clip");
        buttond = new JButton("Drop");
        buttonc = new JButton("Clear Box");
        buttonda = new JButton("Drop All");
        Bottom.add(scroll1);
        Bottom.add(buttona);
        Bottom.add(buttond);
        Bottom.add(buttonc);
        Bottom.add(buttonda);
        Top.add(scroll2);
        Box All = Box.createVerticalBox();
            All.add(Top);
            All.add(Box.createVerticalStrut(5));
            All.add(Bottom);
        contentPane.add(All);
        buttonL cl = new buttonL();
        buttona.addActionListener(cl);
        buttond.addActionListener(cl);
        buttonc.addActionListener(cl);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setSize(424,314);
        ClippedLines.setDragEnabled(true);
      public class buttonL implements ActionListener
        public void actionPerformed(ActionEvent e)
           if(e.getSource() == buttona)
              String elementToAdd = textfield.getText();
              if(elementToAdd.equals("")==false) clippedtxt.addElement(textfield.getText());
           else
             int index = ClippedLines.getSelectedIndex();
             if(index > -1) clippedtxt.remove(index);
           if(e.getSource() == buttonc)
               textfield.setText("");
    }There is a stray dragenabled true line in there which on my ibook showed that it drags after holding the mouse button down a little longer than expected, and it shows im dragging , but obiously not dropping because i haven't configured dropping yet. but on my windows machine it shows nothing of it. oh and, on the ibook it shows it with a green "+" and then makes it look like im trying to put it inbetween two other lines but does nothing when dropped like expected
    Another question: In the beginning of my code i have it loading the entire library with the *, and i noticed after turning it into a .jar that it loads slower than i expected... would a way to speed it up be to specify exactly what i need loaded after the program is finished or would it make no diffrence?
    :-/ seems my program isn't as cross platform as i exptected java to be

    I solved the code problem myself after a careful run through of the code, the "else" in my subclass made it so that every button other than the Add button deleted a selected entry, i quickly fixed it and made it an if statement.
    Thank you for the link cotton.m
    My question bout optimizing still remains though:In the beginning of my code i have it loading the entire library with the *, and i noticed after turning it into a .jar that it loads slower than i expected... would a way to speed it up be to specify exactly what i need loaded after the program is finished or would it make no diffrence?

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • I need to control the position and size of each java swing component, help!

    I setup a GUI which include 2 panels, each includes some components, I want to setup the size and position of these components, I use setBonus or setSize, but doesn't work at all. please help me to fix it. thanks
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.FlowLayout;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.event.*;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.JPanel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.DefaultListModel;
    public class weather extends JFrame {
    private String[] entries={"1","22","333","4444"} ;
    private JTextField country;
    private JList jl;
    private JTextField latitude;
    private JTextField currentTime;
    private JTextField wind;
    private JTextField visibilityField;
    private JTextField skycondition;
    private JTextField dewpoint;
    private JTextField relativehumidity;
    private JTextField presure;
    private JButton search;
    private DefaultListModel listModel;
    private JPanel p1,p2;
    public weather() {
         setUpUIComponent();
    setTitle("Weather Report ");
    setSize(600, 400);
    setResizable(false);
    setVisible(true);
    private void setUpUIComponent(){
         p1 = new JPanel();
    p2 = new JPanel();
         country=new JTextField(10);
         latitude=new JTextField(12);
    currentTime=new JTextField(12);
    wind=new JTextField(12);
    visibilityField=new JTextField(12);
    skycondition=new JTextField(12);
    dewpoint=new JTextField(12);
    relativehumidity=new JTextField(12);
    presure=new JTextField(12);
    search=new JButton("SEARCH");
    listModel = new DefaultListModel();
    jl = new JList(listModel);
    // jl=new JList(entries);
    JScrollPane jsp=new JScrollPane(jl);
    jl.setVisibleRowCount(8);
    jsp.setBounds(120,120,80,80);
    p1.add(country);
    p1.add(search);
    p1.add(jsp);
    p2.add(new JLabel("latitude"));
    p2.add(latitude);
    p2.add(new JLabel("time"));
    p2.add(currentTime);
    p2.add(new JLabel("wind"));
    p2.add(wind);
    p2.add(new JLabel("visibility"));
    p2.add(visibilityField);
    p2.add(new JLabel("skycondition"));
    p2.add(skycondition);
    p2.add(new JLabel("dewpoint"));
    p2.add(dewpoint);
    p2.add(new JLabel("relativehumidity"));
    p2.add(relativehumidity);
    p2.add(new JLabel("presure"));
    p2.add(presure);
    this.getContentPane().setLayout(new FlowLayout());
    this.setLayout(new GridLayout(1,2));
    p2.setLayout(new GridLayout(8, 2));
    this.add(p1);
    this.add(p2);
    public static void main(String[] args) {
    JFrame frame = new weather();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    [http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]
    db

  • Reversing with swing? Help!

    Alright, before you guys flip out and say post it to the swing forum, why does the swing forum say read only? Now I have searched the forum but cannot find anything that deals with swing and the kind I am doing. So if you can provide some advice or some help, it would be greatly appreciated. This is my last hurdle to tackle in my school project.
    I tried a StringBuffer approach but it kept giving me an error saying it would not work with JTextArea? Maybe the code was wrong?
    This needs to take the text on the screen which I have and post it reversed when the "Reverse" button is clicked... I have been searching the web and these forums and all the different reverse methods and theories are confusing me, I try to copy them and get them to work but I just keep receiving errors. What is the best way to do this with using GUI?
    else if (actionCommand.equals("Reverse"))
              reverseMemo = theText.getText();
    /*Is this where I would put the reverse code?*/          
    theText.setText(reverseMemo);
         }Thanks,
    Jess

    Just write a method to reverse the text
    read the string in reverse and start plugging the values into a string buffer (inside a loop of course)
    then display results:
    textfield.setText(stringbuffer.toString());
    This is my last hurdle to tackle in my school project.I highly doubt it.
    The fact you are asking this question shows me you did not learn anything about Java much less computer science. Your question has nothing to do with swing.

  • Menu Bar Code Help

    I am new to Java and am trying to make a menu bar applet for a web page. I think i have the majority of it finished there are three things i could not figure out and i was wondering if someone might be able to help. The things are: Opening Urls in the browser, the color of the highlighter on menu won't change, i want the menu to automatically pop down when the mouse is over the buttons.
    Here is my code so far:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JComponent.*;
    public class MenuApplet extends JApplet implements ActionListener, MouseListener
         public void init()
              /* builds menus */
              JMenuBar WebMenuBar;
              JMenu menu, FinanceSubMenu;
              JMenuItem item1, MenuChoice;
              WebMenuBar = new JMenuBar();
              WebMenuBar.setBackground(Color.RED);
              WebMenuBar.setFont(new Font("SanSerif", Font.BOLD, 14));
              WebMenuBar.setForeground(Color.WHITE);
              WebMenuBar.setBorder(BorderFactory.createRaisedBevelBorder());
              menu = new JMenu();
              menu = createMenu("Finance");
              WebMenuBar.add(menu);
              item1 = new JMenuItem();
                   item1 = createItem("Graphs");
                   menu.add(item1);
                   item1 = createItem("Policies");
                   menu.add(item1);
              FinanceSubMenu = new JMenu("37 Key Exp ");
              FinanceSubMenu.setFont(new Font("SanSerif", Font.BOLD, 14));
              FinanceSubMenu.setForeground(Color.WHITE);
    FinanceSubMenu.setBackground(Color.RED);
                   item1 = createItem("Banbury Raw Exp");
                   FinanceSubMenu.add(item1);
                   item1 = createItem("Curing Raw Exp");
                   FinanceSubMenu.add(item1);
                   item1 = createItem("Waste Disposal");
                   FinanceSubMenu.add(item1);
                   menu.add(FinanceSubMenu);
              menu = createMenu("Engineering");
              WebMenuBar.add(menu);
              menu.getPopupMenu();
              item1 = createItem("Reports");
              menu.add(item1);
              item1 = createItem("Travel");
              menu.add(item1);
              getContentPane().add(WebMenuBar);
         public JMenu createMenu (String name)
              /* creates menus */
              JMenu menu;
              menu = new JMenu(name);
              menu.setBorder(BorderFactory.createRaisedBevelBorder());
              menu.setFont(new Font("SanSerif", Font.BOLD, 16));
              menu.setForeground(Color.WHITE);
              menu.setBackground(Color.RED);
              menu.addMouseListener(this);
              return menu;
         public JMenuItem createItem (String name)
              /*creates menu items */
              JMenuItem MenuChoice;
              MenuChoice = new JMenuItem(name);
         MenuChoice.addActionListener(this);
         MenuChoice.setActionCommand(name);
         /* MenuChoice.setColor; - this also does not work - i want to be able to change the color that
                                                 comes up when the item is highlighted currently it is an ugly gray like color,
                                                 which i know can be done because other
                                                 web pages have it, could not find a method relating to this.
         MenuChoice.setBackground(Color.RED);
         MenuChoice.setFont(new Font("SanSerif", Font.BOLD, 14));
         MenuChoice.setForeground(Color.WHITE);
         return MenuChoice;
         /*processes actions*/
    public void actionPerformed(ActionEvent e)
    if (e.getActionCommand().equals("Graphs"))
                        try
                             URL url = new URL(getDocumentBase(), "http://www.Yahoo.com/");//just to test the URL
                             MenuApplet.getAppletContext().showDocument(url);
                        } catch (MalformedURLException e)
                        /*try
                             URL home = new URL("http://app7-ok-plt/left.htm");
                        URLConnection homeConnection = home.openConnection();
                        } catch (IOException err)
                        System.err.println("Couldn't get I/O for the connection to: home.");
                   System.exit(1);
         else
              if (e.getActionCommand().equals("Policies"))
                        System.out.println("good boy");
         else System.out.println("Not so good");
         public void mousePressed(MouseEvent e)
         /* Empty method definition. */
         public void mouseReleased(MouseEvent e)
         public void mouseEntered(MouseEvent e)
              Object source;
              String test;
              source = e.getSource();
              test = source.toString();
         if(test.endsWith("Engineering]"))
                   System.out.println(e.getSource());
         else if (test.endsWith("Finance]"))
                   System.out.println("well click or something");
         /* Empty method definition. */
         public void mouseExited(MouseEvent e)
         public void mouseClicked(MouseEvent e)
    and here is the html to run it in case you need that:
    <html>
    <head>
    <meta name="GENERATOR" content="Me">
    <meta name="ProgId" content="Stuff">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>top page</title>
    <base target="contents">
    </head>
    <body bgcolor="#FF0000">
    <p>
    <applet code="menuapplet.class" width="80%" height="30">
    </applet>
    </p>
    </body>
    </html>
    Thanks in Advance.

    a scroll bar is not appearing on the left Remove line 11 of stylesheet.css (position:fixed)
    my spry menu is right justified instead of left
    Change line 96 of stylesheet.css to read float:left
    Gramps

Maybe you are looking for

  • Mapping runtime Exception

    I have tested my mapping in IR, it is working good. Problem comes it is receving data from sender system. I have checked the sender side data type and Iam receving the data properly, once the data reaches XI, it could not map it to target structure.

  • Exporting content areas/pages

    Help please!! I have created content areas and pages on the Oracle's hosted portal demo site and need to export them to our own server.. Can anyone advise on how this process is done and if its possible? your help is appreciated... thanks

  • Can't get modbus library to communicate with Modbus RS 485 device

    Hi, I've been trying for a few days now to get the NI modbus library (http://zone.ni.com/devzone/cda/epd/p/id/4756) to work with an Omega CN7500 temperature controller with not much luck.   It works with Omega's own software (using Modbus with a RS23

  • Selection tolorence problem

    I have many images with alpha channels that I need to use as a clipping path. Easy enough. 1. Turn alpha to selection 2. use selection as clipping path. When I turn the alpha to a selection, I want anti-aliasing turned OFF. I want jagged edges. Where

  • Problem with ios4.3.3

    all programs close went I try to start, with the last update iOS4.3.3