2D array of textfields


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: 2D array of textfields

  1. #1
    Join Date
    Dec 2003
    Posts
    3

    Cool 2D array of textfields

    I,m trying to create a application wthat as 100 textfields in the frame, but can,t get the textfields to display,
    any help appreciated
    thanks again

    import java.awt.*;import java.awt.event.*;//import javax.swing.*;public class Minefield extends Frame{ private int rows = 10; private int columns = 10; private TextField[][] tCells = new TextField[rows][columns]; private Frame f1; public Minefield( ) { f1=new Frame(); f1.setSize(350,350); f1.setLocation(100,0); f1.setTitle("MineSweeper"); for(int rowCount = 0; rowCount < rows; rowCount++) for(int columnCount = 0; columnCount < columns; columnCount++) { tCells = new TextField[rows][ columns]; tCells[rowCount][columnCount] = new TextField(); f1.add(tCells[rowCount][columnCount] ); } f1.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); System.exit(0); } }); f1.setVisible(true); } public static void main(String args[]) { Minefield mainFrame=new Minefield(); mainFrame.setSize(300, 300); mainFrame.setTitle("Minefield"); mainFrame.setVisible(false); }}

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    Doing this isn't a problem, but can you please re-post your code properly layed out - it's impossible to read.
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Dec 2003
    Posts
    3

    2D array/textfields

    Sorry about last post,
    I,ll try again

    import java.awt.*;
    import java.awt.event.*;

    public class Minefield extends Frame
    {
    private int rows = 10;
    private int columns = 10;
    private TextField[][] tCells = new TextField[rows] [columns];
    private Frame f1;

    public Minefield( )
    {
    f1=new Frame();
    f1.setSize(350,350);
    f1.setLocation(100,0); f1.setTitle("MineSweeper");

    for(int rowCount = 0; rowCount < rows; rowCount++) for(int columnCount = 0; columnCount < columns; columnCount++)
    {
    tCells = new TextField[rows][ columns];
    tCells[rowCount][columnCount] = new TextField()
    f1.add(tCells[rowCount][columnCount] );
    }
    f1.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent we)
    {
    dispose();
    System.exit(0);
    }
    );
    f1.setVisible(true);
    }

    public static void main(String args[])
    {
    Minefield mainFrame=new Minefield();
    mainFrame.setSize(300, 300);
    mainFrame.setTitle("Minefield");
    mainFrame.setVisible(false);
    }
    }

    cheers

  4. #4
    Join Date
    Dec 2003
    Posts
    10
    Arent you suppose to have panes?

  5. #5
    Join Date
    Dec 2003
    Posts
    3
    No,
    its sorted just needed a layout manager
    don,t need panes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center