Array of buttons .. wut do u thik right?

here is the code i tried to create a bunch of JButtons in the frame ..
wut is between the comments wut i tried and didn't work for me ..
wut is my mistake .. please clearly explain to me .. oh by the way i don't want in my application to set a listener for my buttons ..
i just want to show it ..
regards
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class buttons extends JFrame
     public final int w = 200;
     public final int h = 200;
     JFrame frm = new JFrame();
     //JButton [] set = new JButton (10);
     public buttons ()
          /*for (int i = 0; i=set.length();i++)
                    set.add(i);
          //frm.add(set);
          frm.setSize(200,200);
          frm.setVisible(true);
     public static void main(String[]args)
          new buttons();
}

If you don't want the buttons to do anything, what's the point of having them? Maybe you want labels instead, they are used for displaying text with no interaction.
As far as your code, you need to look at this tutorial:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html
specifically the part about arrays.
     //JButton [] set = new JButton (10);
        JButton[] set = new JButton[10];
     public buttons ()
          /*for (int i = 0; i=set.length();i++)
                    set.add(i);
                for (int i = 0; i=set.length; i++) {
               set[i] = new JButton("whatever text you want");
          }

Similar Messages

  • 'action performed' on array of buttons.

    Hi everyone!
    I am trying to set up an array of buttons on a panel in the main frame of my application. I can get them on to the panel, displaying them correctly but i can;t seem to attach an action performed method to them. Ive attached the following code - if you have any ideas on how to solve this problem i would be very grateful. DO you think it is because they are on this panel and not directly on the main Frame.?
    If i try to attach say Button1_action performed then it clashes with my original button 1!
    Thanks in advance.....
    static int N=10;
    String lett[]={"a","b","c","d","e","f","g","h","i","j"};
    Button button[]=new Button[N];
    for(int k=0;k<N;++k)
    {button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    button[k]_actionPerformed(e);
    this.panel1.add(button[k]);

A: 'action performed' on array of buttons.

viravan is right - your code should work except that button[k]_actionPerformed won't compile. Also, you don't need a separate ActionListener for each button - use a common one and test for the source.
e.g.
import java.awt.*;
import java.awt.event.*;
...code to define Frame, Panel etc...
static int N=10;
String lett[]={"a","b","c","d","e","f","g","h","i","j"};
Button button[]=new Button[N];
ActionListener common = (new ActionListener() {
     public void actionPerformed(ActionEvent e) {
            Button source = (Button)e.getSource();
             System.out.println("Label of button pressed = " + source.getLabel() );
for(int k=0;k<N;++k) {
    button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(common);
    panel1.add(button[k]);
}Another alternative is to addActionListener(this) and code the actionPerformed method as part of the Frame class.

viravan is right - your code should work except that button[k]_actionPerformed won't compile. Also, you don't need a separate ActionListener for each button - use a common one and test for the source.
e.g.
import java.awt.*;
import java.awt.event.*;
...code to define Frame, Panel etc...
static int N=10;
String lett[]={"a","b","c","d","e","f","g","h","i","j"};
Button button[]=new Button[N];
ActionListener common = (new ActionListener() {
     public void actionPerformed(ActionEvent e) {
            Button source = (Button)e.getSource();
             System.out.println("Label of button pressed = " + source.getLabel() );
for(int k=0;k<N;++k) {
    button[k]=new Button();
    button[k].setLabel(lett[k]);
    button[k].setBackground(Color.darkGray);
    button[k].addActionListener(common);
    panel1.add(button[k]);
}Another alternative is to addActionListener(this) and code the actionPerformed method as part of the Frame class.

  • Mechanical Action of an array of buttons

    I have an array of buttons that get dynamically built when the front panel is loaded. When I select one of the buttons it remains "pressed in". If I right click on the button the "Mechanical Action" is greyed out. I pulled the button out of the array and checked the settings and its set to latch when released, its just not happening. Is their any way to set this property?

    Hi Rob,
    enclosed you will find two other solutions, simulating a radio button array based on a standard button array,
    this solution use a event loop.
    Version 1: Simulates Radio Buttons without "Allow False" Option
    Version 2: Simulates Radio Buttons with "Allow False" Option
    Attachments:
    ButtonArray1.vi ‏10 KB
    ButtonArray2.vi ‏10 KB

  • Connecting kurzweil sp88 to GB I want to connect my Kurzweil sp88 to GB. The Kurzweil has a baffling array of buttons and possible MIDI channels. It also has the old style MIDI plug ins. I've got the MIDI out connected to my MacBook Pro via USB adapter.

    I have my Kurzweil connected to my MacBook Pro via an adapter (old style MIDI from Kurzweil to USB adapter connecting to Mac). The Kurzweil has a baffling array of buttons and possible MIDI channels. Can anyone please tell me which of the channels I should use? Also, should I leave the MIDI In cable out of the Kurzweil? Thanks for as detailed an answer as possible. If you like you can respond directly to me at [email protected]

    First of all I do not own this keyboard. But a quick look at the manual (found on the internet) says that when first powered up the SP88 is in Internal Sounds mode. Meaning you hear the sounds selected when playing the keyboard. It also stated that the default Midi Transmit Channel is Midi Channel #1.
    Looks like you would need to go to the SP88 Keyboard's MIDI SETUP and simply select LOCAL OFF. Now the keyboard should be ready to transmit Midi Out only and no internal sounds should be heard.
    Next you may or may not need to do this but you might need to go into the Utilities Folder found in your Applications Folder on your Mac and double click AUDIO MIDI SETUP the keyboard Icon. Figure #1 below.
    Next you need to make a physical connection from the Midi Out of the SP88 to the Midi In on your Midi Interface. Figure #3 below. You may need to Click on Add Device first. Figure #2 below.
    In the examples shown below I have a Yamaha Electronic Drum Kit that is Midi Out only... not USB out. I had to plug a Midi cable from the Midi Out Port on the back of my Drum Module to the Midi In Port on the back of my Motu 828 Audio Inferface which is connected to my Mac. Next I created the Audio Interface and Drum Module "Devices" as mentioned above.
    I then double clicked on the Drum Module and made my Midi Out Selections. Figure #4 Below. And once it was setup and the icons closed I used my mouse to draw a virtual cable connection from the Drum Module Out to the Audio Interface In. Figure #3 below. This is how I got my Midi Devices to talk to one another.
    Once you have made your setup as I have outlined create a MIDI Instrument Track in Garageband, select an instrument for example a Piano then Record Enable that track in Garageband and see if you now hear what you are playing. In this example the SP88 is a Midi Controller only and you will only hear sounds selected in Garageband which is what you want.
    Keep in midi your setup may be different than mine. You can keep your SP88 Keyboard on the default Midi Channel #1. That would be a good place to start. Garageband receives Midi on all channels.

  • Array of buttons return indexof?

    Hi,
    I have an array of buttons. How do I get the value of the array so i know which button the user clicks on. If they click on button 10 i need to get the value 10. I cant copy and past the code here because its too long.If someones interested i can email the code and what i'm trying to do. If someone could give me a generic example of a situation that would be great.
    Thanks in advance

    public class KeyPadDemo extends Frame {
         KeyPad keyPad;
         TextArea textArea;
         public static void main(String[] args){
              new KeyPadDemo();
         public KeyPadDemo(){
              this.setSize(300,300);
              this.setLayout(new BorderLayout());
              this.add(textArea = new TextArea(), "North");
              this.add(keyPad = new KeyPad(textArea),"Center");
              this.setVisible(true);
    class KeyPad extends Panel{
         MyButton buttonZero, buttonOne, buttonTwo, buttonThree, buttonFour, buttonFive, buttonSix;
         MyButton buttonSeven, buttonEight, buttonNine, buttonDecimal, buttonZeroZero;
         TextArea outputArea;
         KeyPad(TextArea outputArea){
              this.outputArea=outputArea;
              setLayout(new GridLayout(4,3));                    //GUI number button pad
              add(buttonSeven = new MyButton("1"));
              add(buttonEight  = new MyButton("2"));
              add(buttonNine = new MyButton("3"));
              add(buttonFour = new MyButton("4"));
              add(buttonFive = new MyButton("5"));
              add(buttonSix = new MyButton("6"));
              add(buttonOne = new MyButton("7"));
              add(buttonTwo = new MyButton("8"));
              add(buttonThree = new MyButton("9"));
              add(buttonZero = new MyButton("0"));
              add(buttonDecimal  = new MyButton("."));
              add(buttonZeroZero = new MyButton("00"));
         class MyButton extends Button implements ActionListener{
              String string;
              public MyButton(String string){
                   super(string);
                   this.string=string;
                   addActionListener(this);
              public void actionPerformed(ActionEvent e){
                   outputArea.append(string);
    }

  • 9x9 array of buttons and not a single button worked

    im trying to build a 9 x 9 block composed of buttons. I used array of buttons.
    here's my code with my explanation and poor logic thinking details.
    public class ButtonArrayDemo extends JFrame implements ActionListener
    private JButton[] sButton;
    private int[] x;//manipulation purposes only
    public ButtonArrayDemo()
         JPanel buttonPanel = new JPanel();
         buttonPanel.setLayout( new GridLayout(9, 9) );
         sButton = new JButton[81];
         x = new int[81];
    // creates the buttons,action listeners, syntax is correct but
    // i doubt the logic
         for (int i = 0; i < sButton.length ; i++)
              JButton button = new JButton();
              button.setText(" ");
              button.addActionListener(this);
              sButton[i] = button;
              buttonPanel.add(sButton);
              x[i] = 0;
         getContentPane().add(buttonPanel,BorderLayout.SOUTH);
         setResizable(false);
    // what i want for this is that, when a button is clicked, it displays the
    //number 1 then increments by 1 if clicked again. Like,when i click a
    //blank button, it displays the number "1", if i clicked it again, it displays
    //the number 2. This goes on until number 9. When the button is clicked
    //on the 10th time, it leaves the button's text blank. Syntax is fine but
    //i doubt the logic.
    public void actionPerformed(ActionEvent e)
         int y;
         for(y = 0; y < sButton.length; y++)
              if(e.getActionCommand().equals(sButton[y]))
                   sButton[y].setText(Integer.toString(++x[y]));
                   if(x[y] == 10)
                   sButton[y].setText(" ");
                   x[y] = 0;
    Now, i created the main and compiled the program. The frames appeared complete with 81 buttons. But, when I click on any button,
    it does nothing. The button's text which is supposedly to change is not displaying anything. this is a vital thinking process for me and any help from someone would be very much appreciated.
    thanks for reading and i hope someone will respond to my problem.
    lots of thanks.

    I believe the problem is that you are using the actionCommand but you did not set the actioncommand for the buttons. I suggest you either set the action command for each button to a unique item or use getSource instead.
    Also, you might want to break out of your for loop once you find the correct button.
    Also, if the future use the code formatting tags and this probably should have been in the Swing forum.

  • Array of buttons and Event Structure

    I have a the same problem... I was wondering if you were able to find a soln.
    I have literally thousands of buttons and each button as a unique key code and unique name.
    For Example :  
    Button Name    – Key code #
    PUSH              - 1
    POP                 - 2
    PULL               - 3
    The way I program this simple algorithm is deadly painful. 
    1)      I create 1000 buttons by going to control->buttons.
    2)      Then I have to go through one by one to change the Boolean text to “PUSH,POP,PULL…”  
    3)      Then used the Event Structure, adding in all the controls names “PUSH, POP, PULL..” In side each event, I placed the key codes “1,2,3..”
    I have search and tried for weeks to find a better way, and still nothing comes to mind.  
    Please help.

    Hi Ben,
    Thank you for your reply, I have attached my try_code and a picture of the code I currently have.  I  am new in Labview, but I am confident that, there must be a easier way to make an array of buttons with different button name and an associated number to that button.  
    The 1st file, is to show you want I am currently doing, (painful)
    The 2nd file attached is some of the things i tried, I had great hope with my try_code, array_jan25.  But I couldn't get it.  I think I am very close.
    Thanks again,
    Attachments:
    ThePainfulWay.doc ‏63 KB
    Array_jan25.vi ‏42 KB

  • Settings button (action) is on the left had side of the Cellular Data is Turned Off notification message put up while the OK button is present on the right hand side of the notification

    The defualt notification message put up when launching iTunes on iPhone devices show that Cellular Data is Turned Off message is put up with Settings and OK button.
    This seems to be inconsistent with the default 'Cancel' and 'Action' buttons in other notification messages from Apple.
    Is it fine to consider the OK button first (left) and Settings(right) button next in the Cellular Data is Turned Off error message in the apps so that it is in line with the apple guidelines??
    Please help with this.
    Thanks you so much.

    Try the basics from the manual.  Restart, reset, restore.

  • Creating array of buttons

    I'm trying to create an array of buttons, but I keep getting a npe
    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl<Container.java:1031>
    at java.awt.Container.add<container.Java:352>
    at ButtonArray.main<ButtonArray.java:26>
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ButtonArray{
    static JLabel jl;
    public static void main(String[] args){
    JFrame jf = new JFrame();
    JPanel p1 = new JPanel();
    JPanel p2 = new JPanel();
    jl = new JLabel();
    int count = 30;
    JButton[] jbh;
    jbh = new JButton[count];
    //JButton[] jbh = new JButton[]{new JButton("1"), new JButton("2")};
    for(int x=1; x<count; x++) {
         jbh[x] = new JButton(Integer.toString(x));
    Container c = jf.getContentPane();
    for(int i = 0; i < jbh.length; ++i){
    p1.add(jbh);
    for(int i = 0; i < jbh.length; ++i){
    jbh[i].addActionListener(new ButtonListener());
    c.add(p1, BorderLayout.NORTH);
    p2.add(jl);
    c.add(p2, BorderLayout.SOUTH);
    jf.setSize(400,300);
    jf.setVisible(true);
    jf.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent evt){
    System.exit(0);
    static class ButtonListener implements ActionListener{
    public void actionPerformed(ActionEvent evt){
    jl.setText("Button" + evt.getActionCommand() + " was pressed");

    Just spotted the error.
    Your for loop adding buttons to the array begins at 1. Therefore there is a null still in position 0 of your array which you attempt to access in your next for loop.
    [shakes fist at Enc]
    Edited by: flounder on Aug 7, 2009 11:08 AM

  • Array of buttons with different boolean text ?

    I'm looking for a method of displaying a 2D button matrix with
    different boolean text on each button. It seems an array of booleans
    must all have the same text. Perhaps a cluster could be used, but the
    array makes button alignment easy and easy to determine which had been
    pressed (radiobutton style with only one button true at a time).
    Steve

    On 6 Dec 2002 05:31:21 -0800, [email protected] (humenik) wrote:
    >[email protected] (Steve Parus) wrote in message news:<[email protected]>...
    >> I'm looking for a method of displaying a 2D button matrix with
    >> different boolean text on each button. It seems an array of booleans
    >> must all have the same text. Perhaps a cluster could be used, but the
    >> array makes button alignment easy and easy to determine which had been
    >> pressed (radiobutton style with only one button true at a time).
    >It's easy to make them individuals in a cluster, and on the block
    >diagram use Cluster To Array to get it into array form for
    >manipulation. This can be superior to an array of buttons, not merely
    >because the buttons can thereby have differing colors and text. An
    >array of buttons cannot have the buttons Latched When Pressed; when in
    >a cluster, however, the latching action is available.
    When might that Latched When Pressed behavior be useful ? Using a 2D
    array of buttons (not cluster), in LV 6.1, a Value Changed event for
    the array can be used as you mention below to XOR the event's OldValue
    and NewValue and wire that to a local variable copy of the array.
    This easily gives a radio button effect for the entire 2D button
    matrix. The array control automatcially arranges the visual
    alignment of the buttons.
    For the cluster method, I'd like to programmatically change which
    button is true. All the approaches I come up with end up using
    Array-to-Cluster which then requires the cluster size to be specified.
    I may end up wanting to programmatically vary the number of buttons in
    both dimensions and hence the cluster size. LV's Align Objects and
    Distribue Objects ends up making the button visual alignment not
    difficult (for a 12 x 8 matrix).
    >Try this: take a cluster of four PB's (latched when pressed) put
    >inside a while loop. Initialize a boolean array of 4 to FALSE outside
    >the while loop, and attach it to a shift register input on the left
    >side of loop. Inside the loop, convert your cluster to an array. XOR
    >the shift register with this array from the buttons, and wire this to
    >the output shift register and to an indicator array. Set the boolean
    >to the loop so it will run free and start it up; on the control panel,
    >click on the PB's and you will see the outputs toggle.
    >
    >Greg

  • Pass a variable number into an Action method from an array of buttons

    Hello,
    I have created an array of buttons like so:
                       private javax.swing.JButton[] barray = new JButton[8];
    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(K8055_Card_Control.JavaElectrodeSwitches1App.class).getContext().getActionMap(JavaElectrodeSwitches1View.class, this);
                 for (int i=0;i<8;i++)    // Create Output Check Boxes
              barray[i] = new JButton();
                            barray.setAction(actionMap.get("ButtonPressed"));
              barray[i].setName("Outbox"+ String.valueOf(i+1));
              barray[i].setText("Electrode " + String.valueOf(i+1));
    BoxLayout layout = new BoxLayout(jPanel1,BoxLayout.PAGE_AXIS);
    barray[i].setAlignmentX(JCheckBox.CENTER_ALIGNMENT) ;
    jPanel1.setLayout(layout);
    jPanel1.add(barray[i]);
    When a button is pressed it calls the method ButtonPressed()@Action
    public void ButtonPressed()
    // button pressed code here
    My problem is that once the button has been pressed I don't know how to find out which button called the method. Each button operates a different switch.
    I tried testing barray.isSelected(); however the ButtonPressed() method is only called once the button has released and is no longer selected.
    Any ideas?
    Thanks,

    Actually the answer to both of these questions is ActionEvent
    do for instance:
    JButton b = new JButton("test");
    JButon b2 = new JButton("test2");
    ActionListener al = new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
      Object src = ae.getSource();
      String cmd = ae.getActionCommand();
      if (src == b) { //won't work unless you make b final
      //or
      if ("test".equals(cmd)) {
    b.addActionListener(al);
    b2.addActionListener(al);

  • Getting the index of the button pressed in an array of buttons

    Hi,
    I have an array of buttons.
    JButton buttons[];
    buttons = new JButton[18];
    for(int idx = 0; idx<buttons.length; idx++)
    buttons[idx] = new JButton("changing button name");
    buttons[idx].addActionListener(this);
    locationButtonGrid.add(buttons[idx]);
    locationButtonGrid.validate();
    I need to know the index of the button pressed. I can't work from the string that is to be sent to the actionListener as this is going to be coming from a database and changing all the time. The idea behind it is that I am narrowing a list of entries down in a database by dividing it into 18 different sections, then dividing that section into 18 different sections and so on.
    I need to know which of the 18 buttons was pressed. Is this possible?
    Please let it be so!
    Cheers,
    elmicko

    Try this (my code is in bold):
    JButton buttons[];
    buttons = new JButton[18];
    for(int idx = 0; idx<buttons.length; idx++)
    buttons[idx] = new JButton("changing button name");
    buttons[idx].addActionListener(this);
    buttons[idx].setID( String.valueOf( idx ) );
    locationButtonGrid.add(buttons[idx]);
    locationButtonGrid.validate();
    In the listener (assuming event is evt):
    buttons[ Integer.parseInt(evt.getSource().getID()) ]
    or
    int idx = Integer.parseInt(evt.getSource().getID());
    buttons[idx]
    finally, if you want to modify the button when you get the event, you can just call the JButton methods by casting the source to a JButton and working from there.

  • Array of buttons help please

    Hi,I'm creating a calendar/diary program and i need help with the following:
    I have 3 classes. One called Calendar_Notetaker.java. This one is the main applet class. The other called MonthDate.java. This class figures out the number of days in month, leap year ect. using the java.util.date. Then another class called CalendarPanel.java. This class creates the actual caladar.
    I used a button array to print the days. However i'm having problems accessing the buttons. i need to put an actionlister on them so when a user clicks on them it opens a new window. i know how to open a new window from a button but i cant figure out how to do it from a button array. Do i need need to create an instance from the main applet or can i do it in the class that generates the buttons?
    here are my classes..note these are all in sepearte files.
    any suggestions would be appreciated
    thanks
    Kevin
    PS. These were done in Borland Jbuilder 7 Enterprise
    package calendar_notetaker;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Calendar_NoteTaker extends Applet {
    private int currentYear;
    private int currentMonth;
    private MonthDate myMonth;
    CalendarPanel monthPanel;
    private boolean isStandalone = false;
    //Get a parameter value
    public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
    (getParameter(key) != null ? getParameter(key) : def);
    //Construct the applet
    public Calendar_NoteTaker() {
    //Initialize the applet
    public void init() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    setLayout(new BorderLayout());
    myMonth = new MonthDate();
    currentYear = myMonth.getYear();
    currentMonth = myMonth.getMonth() + 1;
    monthPanel = new CalendarPanel(myMonth);
    add("Center", monthPanel);
    Panel panel = new Panel();
    panel.add(new Button("Previous Year"));
    panel.add(new Button("Previous Month"));
    panel.add(new Button("Next Month"));
    panel.add(new Button("Next Year"));
    add("South", panel);
    show();
    public void setNewMonth()
    myMonth.setMonth(currentMonth - 1);
    myMonth.setYear(currentYear);
    monthPanel.showMonth();
    public boolean action(Event event, Object obj)
    if(event.target instanceof Button)
    if("Previous Month".equals(obj))
    if(--currentMonth < 1)//goes before january
    currentYear--;
    currentMonth = 12;
    if(currentYear < 70)//year < 1970
    currentYear = 70;
    } else
    if("Next Month".equals(obj))
    if(++currentMonth > 12)//if you go past 12 months
    currentYear++;//set to next year
    currentMonth = 1;//set back to january
    if(currentYear > 137)//137 years from current year.
    currentYear = 137;
    } else
    if("Previous Year".equals(obj))
    if(--currentYear < 70)
    currentYear = 70;
    } else
    if("Next Year".equals(obj) && ++currentYear > 137)
    currentYear = 137;
    setNewMonth();
    return true;
    //Start the applet
    public void start() {
    //Stop the applet
    public void stop() {
    //Destroy the applet
    public void destroy() {
    //Get Applet information
    public String getAppletInfo() {
    return "Applet Information";
    //Get parameter info
    public String[][] getParameterInfo() {
    return null;
    package calendar_notetaker;
    import java.awt.*;
    import java.util.Date;
    public class CalendarPanel extends Panel
    private MonthDate myMonth;
    Label lblMonth;//month label
    Button MonthButtons[];//button arrary for month names
    public CalendarPanel(MonthDate monthdate)
    lblMonth = new Label("",1);//0 left 1 midele 2 right side
    MonthButtons = new Button[42];//42 buttons 7x6 some wont be used
    myMonth = monthdate;
    setLayout(new BorderLayout());
    add("North", lblMonth);
    Panel panel = new Panel();
    panel.setLayout(new GridLayout(7, 7));//7rows x 7cols
    for(int i = 0; i < 7; i++)
    panel.add(new Label(MonthDate.WEEK_LABEL));
    //0 to 42 monthbuttons above is 42
    for(int j = 0; j < MonthButtons.length; j++)
    MonthButtons[j] = new Button(" ");
    panel.add(MonthButtons[j]);//add the butttons to the panel
    showMonth();
    add("Center", panel);
    show();
    public void showMonth()
    lblMonth.setText(myMonth.monthYear());//monthyear is built in util.date
    int i = myMonth.getDay();//get current day
    if(myMonth.weeksInMonth() < 5)//if month has less than 5 weeks
    i += 7;//we still want to have a 7x7 grid
    for(int j = 0; j < i; j++)
    {//add the begging set of empty spaces
    MonthButtons[j].setLabel(" ");
    MonthButtons[j].disable();
    // k<days in month user picks
    for(int k = 0; k < myMonth.daysInMonth(); k++)
    {//add days in month + empty spaces
    MonthButtons[k+ i ].setLabel("" + (k + 1));
    MonthButtons[k+ i ].enable();
    for(int l = myMonth.daysInMonth() + i; l < MonthButtons.length; l++)
    {//add ending number of empty spaces
    MonthButtons[l].setLabel(" ");
    MonthButtons[l].disable();
    package calendar_notetaker;
    import java.util.Date;
    public class MonthDate extends Date
    //week header
    public static final String WEEK_LABEL[] = {
    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
    //days in month assuming feburary is not a leap year
    final int MonthDays[] = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
    30, 31
    //label to print month names
    public static final String MONTH_LABEL[] = {
    "January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
    "November", "December"
    //create constructor
    public MonthDate()
    this(new Date());
    public MonthDate(Date date)
    {//get the current system date and month add one cause its off one
    this(date.getYear(), date.getMonth()+1);
    public MonthDate(int year, int monthName)
    super(year,monthName-1,1);//year, monthname,start day posistion
    public boolean isLeapYear()
    int year;
    Date date = new Date();
    year=date.getYear();
    return ( ((year % 4 == 0) && (year % 100 != 0))
    || (year % 400 == 0) );
    public int daysInMonth()
    int i = getMonth();
    if(i == 1 && isLeapYear())
    return 29;
    } else
    return MonthDays;//return the array declared above
    public int weeksInMonth()
    { //finds howmany weeks are in a month
    return (daysInMonth() + getDay() + 6) / 7;
    public String monthLabel()
    { //method to return the month names for printing later
    return MONTH_LABEL[getMonth()];
    public String monthYear()
    {//method to return the month and year for printing later
    return monthLabel() + " " + (1900 + getYear());

    add a listener and do it from there.

  • How can I get the menu bar?pressing Alt button does not show it, right clicking in a space in the tab does not show customize button.

    I read the information on the help pages,but I can t get the menu bar to appear using the advice given.

    Right click the Home button.

  • Array of buttons

    Hi everyone,
    I'm developing an app where I have a number of buttons, let's say 10. I named them button0, button1, ..., button9. Is there a way to cycle through all of them in a for loop?
    so instead of
    button0 setTitle:@"button 0" forState:UIControlStateNormal ;
    button1 setTitle:@"button 1" forState:UIControlStateNormal ;
    button9 setTitle:@"button 9" forState:UIControlStateNormal ;
    I could set up an array of titles and get a for loop going like this (this is PSEUDO CODE)
    for(int i = 0 ; i <= 9 ; i++)
    [(button + i) setTitle:[[titlesArray objectAtIndex:i] stringValue] forState:UIControlStateNormal];
    Any help would be truly appreciated!
    Thanks,
    Rolando

    orangekay wrote:
    uprise78 wrote:
    [butt doSomething];
    If you have to send this message you should consider more fiber in your diet.
    ROFL!!

  • Maybe you are looking for