Using array create JLabel

i have one problem about using addKeyListener, i'm using array to create JLabel but once i've compile it, it came out a message as i shown, so where is my problem, hope someone can fix it for me and explain it for me, thank you
---------- Capture Output ----------
"C:\Program Files\Java\jdk1.6.0_03\bin\javac.exe" Login.javaLogin.java:78: not a statement
inputTextName[1]KeyPressed( event );
^
Login.java:78: ';' expected
inputTextName[1]KeyPressed( event );
^
2 errors
Terminated with exit code 1.---------- Capture Output ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Login extends JFrame
     //JLabel[] lblName = {"lblName1","lblName2"};
     JLabel[] labelName;
     //JTextField[] txtfldName = {input1,input2};
     JTextField[] inputTextName;
     //JLabel[] array = new JLabel[veryLargeNumber];
     JButton[] btnName = new JButton[3];
public void userInterface()
     this.setBackground(Color.blue);
     this.setTitle("Log in");
     this.setSize(285,130);
     this.setVisible(true);
     Container contentPane = getContentPane();
     contentPane.setLayout(null);
     labelName[0] = new JLabel();
     labelName[0].setText("ID: ");
     labelName[0].setBounds(16, 16, 130, 21);
     this.add(labelName[0]);     
     inputTextName[0] = new JTextField();
     inputTextName[0].setText(" ");
     inputTextName[0].setBounds(50, 16, 150, 21);
     inputTextName[0].setHorizontalAlignment(JTextField.LEFT);
     this.add(inputTextName[0]);
     labelName[1] = new JLabel();
     labelName[1].setText("Password: ");
     labelName[1].setBounds(16, 48, 104, 21);
     this.add(labelName[1]);
     inputTextName[1] = new JTextField();
     inputTextName[1].setText(" ");
     inputTextName[1].setBounds(50, 48, 150, 21);
     inputTextName[1].setHorizontalAlignment(JTextField.LEFT);
     this.add(inputTextName[1]);
     btnName[0] = new JButton();
     btnName[0].setText("login");
     btnName[0].setBounds(120,80,65,20);
     this.add(btnName[0]);
     btnName[1] = new JButton();
     btnName[1].setText("exit");
     btnName[1].setBounds(190,80,65,20);
     this.add(btnName[1]);
     inputTextName[1].addKeyListener(
         new KeyAdapter() // anonymous inner class
            // method called when user types in cartonsJTextField
            public void keyPressed( KeyEvent event )
              inputTextName[1]KeyPressed( event );
         } // end anonymous inner class
      ); // end call to addKeyListener
//call function
     public Login()
          userInterface();          
     public static void main (String args[])
          Login application = new Login();
           application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
     }Edited by: slamgundam on Oct 24, 2007 11:48 PM

slamgundam wrote:
the purpose is try to get the text in the inputTextField
inputTextName[1].addKeyListener(
    new KeyAdapter()
         // method called when user types in cartonsJTextField
         public void keyPressed( KeyEvent event )
               String str = inputTextName[1].getText();
               System.out.println(str);
);

Similar Messages

  • Creating tables using arrays.

    Hi, i have 3 arrays whose size may differ depending on a text file. I used vectors and string tokenizers to read the data and split them into 2 vectors, The third one is an array created from the values in vector2 using a formula. Now, I need to create a table with the 3 columns and the number of rows depending on the length of the array3 which is the same as vector 1 and vector2.
    How do i do that? The col1 in the table shoud have the data in vector1, col2 should have data in vector2 and col 3 should have data in array3.
    Please help me in this
    Thanks

    I have to display this data in the form of a "table"
    where the data in the columns are the data in the
    three arrays. I have to display this is an array. I believe you can create an array from a List, and a Vector is a List.
    Look at java.util.*. If this is what you mean.
    The problem is, the size of vectors depends on various
    calculations. so it is not the same everytime. So i
    need to display the data depending on the vector's
    size.How is this a problem? You can get the size from the vector, then use that for whatever kind of table you're making, probably. I still have no idea what kind of table you mean.

  • Array of JLabel HELP

    how would I create an array of JLabels?

    If you are not sure of how many object you want to place within the array, ArrayLists can grow dynamically. Here is how to use it:
    java.util.ArrayList arraylist = new java.util.ArrayList();
    //To Add Your Class:
    YourClass yourClass = new YourClass();
    arraylist.add(yourClass);
    //To Use Your Class:
    YourClass yourClass = (YourClass)arrayList.get(0);

  • Possible to make arrays of JLabels?

    I would like to make arrays of JLabels, Iconimages, and Jpanels, but I can't find how to do it.
    Is it eaven possible?
    How can I proceed instead...?

    Why not????
    Infact you can make an array of any premitive type or of any object... Just you need to use this syntax...
    dataType[] arrVarName = new dataType[size];
    for example,
    JLabel[] lblArr = new JLabel[10];
    This will create the new array of JLabel type of 10 elements size... You can initialize each element like this:
    for(int i = 0; i < lblArr.length; i++){
    lblArr[i] = new JLabel("Hello " + i);
    and you can print each element like this:
    for(int i = 0; i < lblArr.length; i++){
    System.out.println(lblArr.getText());
    Okay... Still if you are having any doubt you are always welcome

  • Help using arrays in java

    HI all,
    I am working on a program that will print out my initials 'A' and 'T' using arrays. I am asked to initialize the first intial to '*' and the second intial to '@'. I wrote the code but the output is wrong. Can someone help me by letting me know what I am doing wrong in my arrray?I just get back my array of 30X30. I also wrote a driver but when I run the program, I really appreciate it so much.
    public class Initial
         private char whichinitial ;
         private int MAX =30;//Maximum amount for 2-d Matrix
         char[][] letterMatrix = new char[MAX][MAX];//2-d Array 30 x30
         private boolean first = true;
         public Initial()
         { //FIlls Array full of '*'s
              whichinitial = '*';
              for(int i=0;i< MAX;i++)
                   for(int j=0;i< MAX;i++)
                        letterMatrix[i][j] = whichinitial;
         public void setLetter(char letter)
         {//Setter for Letter
               whichinitial = letter;
         public char getLetter()
         {//Getter for Letter
              return whichinitial;
         public void firstLetter()
         { //Creates an A shape
              for(int i=0;i< MAX;i++)
                for(int j=0;j< MAX;j++)
                      if((i>0)|| ((i<6) || ((j>0) && (j<29))))
                         letterMatrix[j] =whichinitial;
         public void secondLetter()
         {//Creates an T shape
              first = false;
                   for(int i=0;i <MAX;i++)
                   for(int j=0;j <MAX;j++)
                        if((i>1) ||(j < 29)||(j>5)||(i>10))
                             letterMatrix[i][j] = whichinitial;
         public void display()
         {//Displays the Initials
              if(first)
                   System.out.println("\n \n \n My First Initial," + whichinitial + ", follows:");
              else
                   System.out.println("\n \n \n My Last Initial," + whichinitial + ", follows:");
                   for(int i=0;i <MAX;i++)
                        System.out.println();
                        for(int j=0;j <MAX;j++)
                             if(letterMatrix[i][j] == '*')
                                  System.out.print(" ");
                             else
                                  System.out.print(letterMatrix[i][j]);

    I am trying to write a program using a matrix. The size of the maxtrix should be 30X30. The first initial shoulld be initialized to '*' and the secind initial should be initialized to '@'. Both initials should be 30 characters high and 30 characters wide and the initials should also represent the uppercase letter of your initials. I know that the first initial's matrix needs to be filled up vertically and the second initial needs to be filled horizontally but the output is wrong....PLease Help!
    Message was edited by:
    apples03

  • Using Arrays in a program

    First, I would like to thank everyone in this forum for all the help they have given me over the past few weeks. With that said, I am currently trying to alter the following code to accept and use arrays to end to produce three seperate results. The program now as three hard coded variables which are
    Amount = 200000.00;
    Term = 30;
    InterestRate = .0575;
    I need to have the program work the same, but produce results for three different Terms and Three different periods. Below is the code the I am working on, I have added two arrays containing the required information. I am having a hard time coming up with a for statment to move the program through the two arrays. Any pushes in the right direction would be great. I left the hard code variable in place, I know that I do need to remove them and alter the equations. I just thought it would be easier for everyone to understand if I left the code in working form.
    import java.math.*;
    import java.text.*;
    import java.util.*;
    // The Payment class displays a predetermined monthly mortgage payment
    public class Payment
         public static void main(String[]arguments)
              //Creates Two Arrays for InterestRates and Terms
              double[] InterestRates = {.0535, .055, .0575};
              int[] Terms = {7, 15, 30};
              //Creates variables
              double Amount;
              int Term;
              double InterestRate;
              //Assigns values to variables
              Amount = 200000.00;
              Term = 30;
              InterestRate = .0575;
              //Alters the display format of Amount variable
              NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
              String s = n.format(Amount);
              //Creates variables
              double MonthlyInterestRate;
              int TotalMonths;
              double Payment;
              //Assigns values to variables
              MonthlyInterestRate = InterestRate / 12;
              TotalMonths = Term * 12;
              Payment = Amount* MonthlyInterestRate / (1-(Math.pow((1+MonthlyInterestRate ),(-TotalMonths))));
              //Takes Payment variable and round answer to 2 decimal points
              BigDecimal bd = new BigDecimal(Payment);
    bd = bd.setScale(2, BigDecimal.ROUND_DOWN);
              //Instructions to display various varibles
              System.out.println("Cost of Mortgage "+ s);
              System.out.println("Length of Term " + Term);
              System.out.println("Interest Rate 5.75% ");
              System.out.println("The monthly payment of this loan is $" + bd);
              System.out.println();
              //Creates new set of variables
              double MonthlyInterest;
              double MonthlyPrincipal;
              double TotalInterestPaid;
              int NumberofPayments;
              //Creates Balance variable
              double Balance;
              //Initialization of Balance variable
              Balance = 200000;
              TotalInterestPaid = 0;
              NumberofPayments = 360;
              //Creates a loop that calculates the entire term of loan
              do
              MonthlyInterest = Balance * (InterestRate / 12);
              MonthlyPrincipal = Payment - MonthlyInterest;
              Balance = Balance - MonthlyPrincipal;
              TotalInterestPaid = TotalInterestPaid + MonthlyInterest;
              NumberofPayments = NumberofPayments - 1;
              //Takes current balance and rounds the answer to two digits
              BigDecimal bb = new BigDecimal(Balance);
    bb = bb.setScale(2, BigDecimal.ROUND_DOWN);
              BigDecimal tip = new BigDecimal(TotalInterestPaid);
                        tip = tip.setScale(2, BigDecimal.ROUND_UP);
              System.out.println("New Loan Balance " + bb);
              System.out.println();
              System.out.println("Total Interest Paid " + tip);
              System.out.println();
              System.out.println("Number of Payments remaining " + NumberofPayments);
              System.out.println();
              //The following lines of code pauses the loop to allow the user to read the output
              //The speed of th display can be adujusted to a wide variety of speeds
              try
                   Thread.sleep(400);
                   catch (InterruptedException exc)
              //Loop condition
              while (NumberofPayments > 0);
    //Ends Application

    Try this. It should give you some ideas. :)
    import java.math.BigDecimal;
    import java.text.NumberFormat;
    import java.util.Locale;
    // The Payment class displays a predetermined monthly mortgage payment
    public class Payment {
        public static final NumberFormat CURRENCY_FORMAT = NumberFormat.getCurrencyInstance(Locale.US);
        public static final double[] INTEREST_RATES = {.0535D, .055D, .0575D};
        public static final int[] TERMS = {7, 15, 30};
        public static final double AMOUNT = 200000.00;
        public static final int MONTHS_PER_YEAR = 12;
        public static void main(String[] arguments) {
            for (int t = 0; t < TERMS.length; t++) {
                for (int i = 0; i < INTEREST_RATES.length; i++) {
                    displayPayments(AMOUNT, INTEREST_RATES, TERMS[t]);
    private static void displayPayments(double amount, double interestRate, int term) {
    //Creates variables
    //Assigns values to variables
    double monthlyInterestRate = interestRate / MONTHS_PER_YEAR;
    int totalMonths = term * MONTHS_PER_YEAR;
    double payment = amount * monthlyInterestRate / (1 - Math.pow(1 + monthlyInterestRate, -totalMonths));
    //Instructions to display various varibles
    System.out.println("Cost of Mortgage " + CURRENCY_FORMAT.format(amount));
    System.out.println("Length of Term " + term);
    System.out.println("Interest Rate " + new BigDecimal(interestRate * 100).setScale(2, BigDecimal.ROUND_HALF_UP) + '%');
    System.out.println("The monthly payment of this loan is " + CURRENCY_FORMAT.format(payment));
    System.out.println();
    //Creates new set of variables
    double totalInterestPaid = 0.0D;
    //Creates balance variable, Initialization of balance variable
    double balance = amount;
    //Creates a loop that calculates the entire term of loan
    System.out.println("New Loan balance, Total Interest Paid, Number of Payments remaining");
    for (int numberofPayment = totalMonths; numberofPayment > 0; numberofPayment--) {
    double monthlyInterest = balance * monthlyInterestRate;
    double monthlyPrincipal = payment - monthlyInterest;
    balance -= monthlyPrincipal;
    totalInterestPaid += monthlyInterest;
    //Takes current balance and rounds the answer to two digits
    BigDecimal bb = new BigDecimal(balance);
    bb = bb.setScale(2, BigDecimal.ROUND_DOWN);
    BigDecimal tip = new BigDecimal(totalInterestPaid);
    tip = tip.setScale(2, BigDecimal.ROUND_UP);
    System.out.println(CURRENCY_FORMAT.format(bb.doubleValue()) + ", " +
    CURRENCY_FORMAT.format(tip.doubleValue()) + ", " +
    numberofPayment);
    System.out.println();
    //Ends Application

  • Using arrays in JAVA

    Hi Guys,
    I always had a few problems using arrays and now I need to use them and I am stuck.
    on my program i need to create an array of int with the numbers 1 to 1000 in it for this I have done:
    int[ ] array;
    on the class constructor
    array = new int[1000];
    to fill the array:
    for (int i = 0; i < array.length; i++)
         array[i] = i;
    The problem is that I always get an ArrayIndexOutOfBoundsException error.
    I know how to solve it which is to create an array with 1001 elements but is there a more elegant way of creating the array or this is the way to do it?
    To put my question in another way if any of you Guys was creating this program which way would you do it.
    Best regards
              Luis

    Sloppy of me. This is a bit better:
    package cruft;
    import java.util.Arrays;
    * A class for a one-based array of ints.
    public class OneBasedIntArray
       private int [] values;
       public static void main(String[] args)
          int [] values = new int[args.length];
          for (int i = 0; i < args.length; i++)
             values[i] = Integer.parseInt(args);
    OneBasedIntArray intArray = new OneBasedIntArray(values);
    System.out.println(intArray);
    public OneBasedIntArray(int[] values)
    this.values = new int[values.length];
    System.arraycopy(values, 0, this.values, 0, values.length);
    public int getValue(int index)
    if (index <= 0)
    throw new IllegalArgumentException("this array is one-based");
    return values[index-1];
    public void setValue(int index, int value)
    if (index <= 0)
    throw new IllegalArgumentException("this array is one-based");
    this.values[index-1] = value;
    public boolean equals(Object o)
    if (this == o)
    return true;
    if (o == null || getClass() != o.getClass())
    return false;
    OneBasedIntArray intArray = (OneBasedIntArray) o;
    if (!Arrays.equals(values, intArray.values))
    return false;
    return true;
    public int hashCode()
    return (values != null ? Arrays.hashCode(values) : 0);
    public String toString()
    StringBuilder builder = new StringBuilder();
    builder.append("OneBasedIntArray{");
    for (int i = 0; i < values.length; i++)
    builder.append("(").append(i+1).append(",").append(values[i]).append(")");
    builder.append('}');
    return builder.toString();

  • Error using Arrays.toString()

    Hi there,
    I am getting the following error using Arrays.toString on a String Array. 'toString() in java.lang.Object cannot be applied to (java.lang.String[]).
    The line in question is at the bottom of the below code. It starts 'rtitem.appendText.....
    import lotus.domino.*;
    //import java.util.Arrays;
    public class JavaAgent extends AgentBase {
         Database curDb;
         String[] dbList;
         public void NotesMain() {
         int dbcount = 0;
              try {
                   Session session = getSession();
                   AgentContext agentContext = session.getAgentContext();
                   //get current database
                   Database curDb = agentContext.getCurrentDatabase();
                   //build a list of servers;
                   String[] servers = {"Norwich002/Norwich/MoneyCentre","Norwich003/MoneyCentre","Norwich004/MoneyCentre","Norwich005/MoneyCentre","Norwich007/Norwich/MoneyCentre","Norwich008/Norwich/MoneyCentre","Norwich010/Norwich/MoneyCentre","Norwich020/Norwich/MoneyCentre","Norwich021/Norwich/MoneyCentre"};
                   //loop through server list
                   int arraylen = servers.length;
                   for(int i=0;i <= arraylen;i++){
                        //create a notesdbdirectory collection for the current server iteration
                        DbDirectory dbdir = session.getDbDirectory(servers);
                        //get first database
                        Database db = dbdir.getFirstDatabase(DbDirectory.DATABASE);
                        //loop through databases in dbdir
                        while (db != null){
                             //add database details to our list
                             dbList[dbcount] = db.getTitle() + " - " + db.getFilePath();
                             dbcount++;     
              } catch(Exception e) {
                   e.printStackTrace();
              private boolean sendEmail(String subject){
                   try{
                        Document mailDoc = curDb.createDocument();
                        mailDoc.replaceItemValue("SendTo","Hayleigh S Mann/Norwich/MoneyCentre");
                        mailDoc.replaceItemValue("Subject",subject);
                        RichTextItem rtitem = mailDoc.createRichTextItem("Body");
                        rtitem.appendText(java.util.Arrays.toString(dbList));
                        mailDoc.send();
                        return true;
                   }catch(Exception e){
                        e.printStackTrace();
                        return false;

    No, that doesn't make any sense. Arrays.toString can take any array as an arg: [http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#toString(java.lang.Object[])]
    import java.util.*;
    public class A {
      public static void main(String[] args) {
        String str = Arrays.toString(args);
        System.out.println(str);
    :; java -cp . A abc 123 xxx
    [abc, 123, xxx]

  • How to use array of Point Class

    I use Point class as array. I already create that. However I can't access to setLocation.
    Ex.
    Point myPoint[] = new Point[10];
    myPoint[0].setLocation(10, 2);
    It has a error.
    Please Explain me.

    DeltaGeek wrote:
    BalusC wrote:
    Or use [Arrays#fill()|http://java.sun.com/javase/6/docs/api/java/util/Arrays.html]. Point[] points = new Point[10];
    Arrays.fill(points, new Point());
    That doesn't do what you think it does, unless you want your array to contain 10 references to the same Point object.The OP has received a good answer, I believe. So it's worth risking diverting this thread into the weeds by pointing out that if Java had closures then BalusC's code could be modified to work.

  • Using Arrays.asList: Is Array[x] == List.get(x)

    I have an Object[] Array and I wish to remove index 'x' from that Object[] Array. If I use Arrays.asList() passing in the existing Object[] Array I will get new List Object containing the objects from the Object[] Array. Is it guaranteed that index 'x' from the Object[] Array is the same Object from the index 'x' in the new List?
    Object[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_3"};
    List list = Arrays.asList(obj);
    assertTrue(obj[0] == list.get(0));
    assertTrue(obj[1] == list.get(1));
    assertTrue(obj[2] == list.get(2));
    assertTrue(obj[3] == list.get(3));Are the above assertions always guaranteed to be true?

    Jared_java_dev wrote:
    I thought the JavaDoc API would state it as well. I did originally check that.
    I agree that it should keep the order but I wanted to verify this behavior. It would make some coding logic much more simple.
    Objective is to remove ojb[2]
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //Perferred logic
    List<String> list = Arrays.asList(obj);
    //remove unwanted element
    list.remove(2);
    //create new Object[] without unwanted element
    obj = (String[]) list.toArray();
    {code}
    as opposed to
    {code}
    String[] obj = new String[] {"obj_0", "obj_1", "obj_2", "obj_
    //unwanted logic
    List<String> list = Arrays.asList(obj);
    for (int x = 0; x < obj.length; x++) {
    // == or String.equals
    if (list.get(x) == (obj[x])) {
            list.remove(x);
    obj = (String[]) list.toArray();I guess that I could write a sample program and run to verify this .
    Thanks for everyone's input.No, you won't be able to simply 'delete' items from this array-backed list. It is a fixed size list, so additions/deletions are expected to throw exceptions.
    So now my question is: Why is the master an array in the first place? Seems like it should be a List from the get-go.

  • Using array to store objects

    i seen array storing many integers, strings, char. but how to use array to store objects of a class..
    how to define those objects created from a defined class in a array. how to obtain each instance variable of the object stored in the array.
    maybe can use a student class to illustrate.

    i got yr idea man!!
    so whenever the compiler see
    String s = "Hola Mundo";
    it is simply equal to String s = new String("Hola
    Mundo");
    that why we can directly access value to array[0]=
    "hi";
    array[0]=new Student();
    array[0].setName = "Hola Mundo"
    is also similar in certain way to
    array[0]= new String("Hola Mundo");
    i right again this time?Nope waaaay off.
    If Name is public in Student then it would be:
    array[0].name = "Hola Mundo";
    if name is private and you have a public setter setName(String newName) then it would be:
    array[0].setName("Hola Mundo");
    and if array is an array of strings, then array[0] = "Hola Mundo";
    is correct.
    PS: you still need to read the tutorials. I am out now.

  • Stack ADT using array

    Hi everyone, I posted a similar question earlier and thought I got the response I wanted but I keep running into problems.
    I'm looking to make my own version of the stack ADT using arrays (or arraylist).
    I have created my own isEmpty() method. Here is part of my code:
    public interface StackADT<T> {
         void push(T element); // adds an element to the stack
         T pop(); // removes an element from the stack and returns it
         boolean isEmpty(); // returns true if the stack is empty and false otherwise
         T peek(); // returns top element from the stack without removing it
         void truncate(); // truncates the stack to the exact number of elements
         void setExpansionRule(char rule); // sets expansion to either doubling or increasing by 10 elements
    public class Stack<T> implements StackADT<T> {
              private T[] array;
              int index = 0;
              public Stack(){
                   this.array = (T[]) new Object[50];
              public boolean isEmpty(){
              if (index == 0){
                   return true;
              return false;
               public T pop(){
                    if(Stack<T>.isEmpty()){  //ERROR
                     throw new EmptyStackException("Stack is empty");     
    }I'm trying to use my isEmpty() method (also part of the stack class) inside other methods like pop(). Problem is it says: "T cannot be resolved to a variable, Stack cannot be resolved to a variable". I also tried Stack.isEmpty(), but it doesn't work. I'm really confused. Any suggestions?
    Edited by: Tiberiu on Mar 1, 2013 6:38 PM

    >
    Hi everyone, I posted a similar question earlier and thought I got the response I wanted but I keep running into problems.
    I'm looking to make my own version of the stack ADT using arrays (or arraylist).
    I have created my own isEmpty() method. Here is part of my code:
    >
    No - you haven't. There is no 'isEmpty' method in the code you posted.
    We can't debug code that we can't see. You haven't posted any interface and you haven't posted anything that calls any of the limited code that you did post.
    You did post code that tries to call the method on the class instead of an instance of the class.
    if(Stack<T>.isEmpty()){ 

  • Getting properties used to create existing connection

    I am a bit stumped trying to figure out how to interrogate an existing java.sql.Connection to see what properties were used to create the connection. If a properties file with name/value pair was used to create the connection I need to find out what value was used for a given property. So far I have been able to get a DriverPropertyInfo array from the driveManager but this only lists the default values, not those I actually used.
    We are having performance issues and I need to analyze connections to verify they were created using the correct properties.
    Thanks in advance for any assisstance.

    Have you looked at the getMetaData() method?
    It has a good bit of information, and maybe it will have whatever property you are looking for.

  • Tic Tac Toe help using array

    Ok i am trying to get a tic tac toe game, which uses array. I need to get 3 buttons and store them then i can check those numbers to see if its a win. Here is my code
       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
        public class project4q3 extends JFrame implements ActionListener {
          private JButton buttons[]=new JButton[9];
          private String names[]={"1","2","3",
                                                "4","5","6",
                                                "7","8","9",};
          private int map[][]= {{1,2,3}, {4,5,6}, {7,8,9}, {1,4,7}, {2,5,8},
             {3,6,9}, {1,5,9}, {3,5,7}};
          private JPanel infoPanel;
          private JLabel player,player2;
          private int row=0,count=0;
          private int whosMove=1;
       // set up GUI and event handling
           public project4q3()
             super( "Tic Tac Toe" );
             infoPanel = new JPanel();
          // two layouts, the upper one is grid style and the
          // lower one is flow style.
             infoPanel.setLayout (new GridLayout(3, 3));
          //Add Button Names
             for(int i=0;i<buttons.length;i++)
                buttons=new JButton(names[i]);
    // direction button objects
    for(int i=0;i<buttons.length;i++)
    buttons[i].addActionListener( this );
    //Grid buttons
    for(int i=0;i<buttons.length;i++)
    infoPanel.add(buttons[i]);
    // grid layout of the main panel, one upper and the other lower
    getContentPane().add(infoPanel);
    setTitle("Tic Tac Toe");
    setSize(400, 400 );
    setVisible( true );
    } // end constructor
    // handle button events because this->actionperformed
    // i.e., (project3q6)->actionPerformed, is added into
    // each button's action
    public void actionPerformed( ActionEvent event ){
    int n1=0,n2=0,n3;
    for(int i=0;i<buttons.length;i++){
    if (event.getSource()==buttons[i])
    n1=Integer.parseInt(names[i]);
    System.out.println(n1);
         System.out.println(n2);
    for(int i = 0; flag == 0 && i< c.length; i++){
              if(n1==c[i][0]&&n2==c[i][1]&&n3==c[i][2]){
                   flag = 1;
              else if (n1==c[i][0]&&n3==c[i][1]&&n2==c[i][2]){
                   flag = 1;
              else if(n2==c[i][0]&&n1==c[i][1]&&n3==c[i][2]){
                   flag = 1;
              else if(n2==c[i][0]&&n3==c[i][1]&&n1==c[i][2]){
                   flag = 1;
              else if(n3==c[i][0]&&n1==c[i][1]&&n2==c[i][2]){
                   flag = 1;
              else if(n3==c[i][0]&&n2==c[i][1]&&n1==c[i][2]){
                   flag = 1;
    // the start of the game
    public static void main( String args[] )
    project4q3 application = new project4q3();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    I couldn't try this out due to a few syntax errors, so fixed some. Now the buttons seem to work.
       import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
        public class project4q3 extends JFrame implements ActionListener {
          private JButton buttons[]=new JButton[9];
          private String names[]={"1","2","3",
                                                "4","5","6",
                                                "7","8","9",};
          private int c[][]= {{1,2,3}, {4,5,6}, {7,8,9}, {1,4,7}, {2,5,8},
             {3,6,9}, {1,5,9}, {3,5,7}};
          private JPanel infoPanel;
          private JLabel player,player2;
          private int row=0,count=0;
          private int whosMove=1;
    private int flag;
       // set up GUI and event handling
           public project4q3()
             super( "Tic Tac Toe" );
             infoPanel = new JPanel();
          // two layouts, the upper one is grid style and the
          // lower one is flow style.
             infoPanel.setLayout (new GridLayout(3, 3));
          //Add Button Names
             for(int i=0;i<buttons.length;i++)
                buttons=new JButton(names[i]);
    // direction button objects
    for(int i=0;i<buttons.length;i++)
    buttons[i].addActionListener( this );
    //Grid buttons
    for(int i=0;i<buttons.length;i++)
    infoPanel.add(buttons[i]);
    // grid layout of the main panel, one upper and the other lower
    getContentPane().add(infoPanel);
    setTitle("Tic Tac Toe");
    setSize(400, 400 );
    setVisible( true );
    } // end constructor
    // handle button events because this->actionperformed
    // i.e., (project3q6)->actionPerformed, is added into
    // each button's action
    public void actionPerformed( ActionEvent event ){
    int n1=0,n2=0,n3=0;
    for(int i=0;i<buttons.length;i++){
    if (event.getSource()==buttons[i])
    n1=Integer.parseInt(names[i]);
    System.out.println(n1);
         System.out.println(n2);
    for(int i = 0; flag == 0 && i < c.length; i++){
              if(n1==c[i][0]&&n2==c[i][1]&&n3==c[i][2]){
                   flag = 1;
              else if (n1==c[i][0]&&n3==c[i][1]&&n2==c[i][2]){
                   flag = 1;
              else if(n2==c[i][0]&&n1==c[i][1]&&n3==c[i][2]){
                   flag = 1;
              else if(n2==c[i][0]&&n3==c[i][1]&&n1==c[i][2]){
                   flag = 1;
              else if(n3==c[i][0]&&n1==c[i][1]&&n2==c[i][2]){
                   flag = 1;
              else if(n3==c[i][0]&&n2==c[i][1]&&n1==c[i][2]){
                   flag = 1;
    // the start of the game
    public static void main( String[] args)
    project4q3 application = new project4q3();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

  • When I want to organise my bookmarks most of the options are greyed out and cannot be used including create new folder! Help

    '''''''''bold text'''''''''
    When i want to organise my bookmarks most of the options on the organise bookmarks menu are greyed out and cannot be used - including create new folder etc. Help please.

    Make sure you are not in the Private Browsing Mode:
    File > Private Browsing is UNCHECKED.

Maybe you are looking for

  • Server Admin- Mail queue is this before or after its been checked as spam?

    Hi we have been bombarded with shed loads of junk causing the mail queue to swell and slow down considerably almost to a halt. I have now created the junkmail account and the notjunkmail accounts and now trying to teach the server to sort itself out.

  • Functional specs for o/p type for depot sales

    hi all, can anybodey provide me with hte fuctional specs for depot sales o/p.the outgoing excise invoice is generated against the MIGO excise number. the same excise invoice number is generated against multiple deliveries. moreover there are no excis

  • Fonts in the Folder panel

    Is there anyway to enlarge the fonts in the folder panel? Favorites is a good size but the folders are very small for viewing. Thanks Jonathan

  • Vendor VAT Number change in the billing document

    In the invoice we have the VAT number of the customer country as well as the vendor VAT number is printed, customer vat no if it is not maintained at customer master we can add it manually or change manually when invocie is created. but the VAT numbe

  • Collecting logs from Cisco Prime Infrastructure

    Hi , I am currently working in integrating  Cisco Prime Infrastruture with the siem tool Qradar. Can any one help me out in below issues: 1)How and where is the log stored in Cisco Prime.? 2)Does the logs contains the logs of the devices that Cisco P