The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with my code

1 reply on 1 page. Most recent reply: Nov 30, 2003 4:42 PM by Absoluteloser

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Char

Posts: 2
Nickname: charbrad
Registered: Nov, 2003

Problem with my code Posted: Nov 30, 2003 9:37 AM
Reply to this message Reply
Advertisement
Hi I have a problem with my code. First let me explain what I am trying to do:

Create 26 buttons each with a letter of the alphabet, then create
swing applet to hold panels in a five by one grid. Each the 1st four
panels have six buttons and the fifth has 2.

Problem.......my grid is 26 panels instead of the five. Here is my code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Alphabet extends JApplet implements ActionListener
{
JButton button5 = null;
JLabel alphaLabel = null;

public void init()
{
Container con = getContentPane();
con.setLayout(new GridLayout());
JPanel panel = new JPanel(new GridLayout(1,5));
JButton button1 = new JButton("A B C D E F");
JButton button2 = new JButton("G H I J K L");
JButton button3 = new JButton("M N O P Q R");
JButton button4 = new JButton("S T U V W X");
JButton button5 = new JButton("Y Z");
alphaLabel = new JLabel(" ALPHABET LETTER ");
button5 = new JButton("Y Z");
panel.add(button5);
button5.addActionListener(this);
panel.add(button1);
p anel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(alphaLabel) ;
JButton a = new JButton("A");
JButton b = new JButton("B");
JButton c = new JButton("C");
JButton d = new JButton("D");
JButton e = new JButton("E");
JButton f = new JButton("F");
JButton g = new JButton("G");
JButton h = new JButton("H");
JButton i = new JButton("I");
JButton j = new JButton("J");
JButton k = new JButton("K");
JButton l = new JButton("L");
JButton m = new JButton("M");
JButton n = new JButton("N");
JButton o = new JButton("O");
JButton p = new JButton("P");
JButton q = new JButton("Q");
JButton r = new JButton("R");
JButton s = new JButton("S");
JButton t = new JButton("T");
JButton u = new JButton("U");
JButton v = new JButton("V");
JButton w = new JButton("W");
JButton x = new JButton("X");
JButton y = new JButton("Y");
JButton z = new JButton("Z");
con.add(a);
con.add(b);
con.add(c);
con.add(d);
con.add(e);
con.a dd(f);
con.add(g);
con.add(h);
con.add(i);
con.add(j);
con.add(k);
con.add(l);
c on.add(m);
con.add(n);
con.add(o);
con.add(p);
con.add(q);
con.add(r);
con.add(s );
con.add(t);
con.add(u);
con.add(v);
con.add(w);
con.add(x);
con.add(y);
con.a dd(z);

}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if (source == button5)
{
alphaLabel.setText("Folder X");

}
}
}


Absoluteloser

Posts: 2
Nickname: dirtyhuman
Registered: Nov, 2003

Re: Problem with my code Posted: Nov 30, 2003 4:42 PM
Reply to this message Reply
While I do not have the answer, I do have something that can make your life easier. You can increment characters so they go up from A to Z using a for loop, like this:

import java.io.*;

public class MrClean
{
public static void main(String[] args)
{
int lame = 65;//the ASCII value of 'A' is 65. You should note that the value of 'a' is different from 'A'
//if you wish to print the value of a letter, you can with this statement:
//System.out.print("The value of 'A' is: " + (int)'A');
for(lame=0;lame<65+25;++lame){
System.out.print((char)lame);
}
}}

Flat View: This topic has 1 reply on 1 page
Topic: Problem with Java Code Previous Topic   Next Topic Topic: Help please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use