How to ouput into JTextArea

Hi, I'm creating a Boggle game in Java and I'm in need of help importing what outputs on the 'status' into the JTextArea called 'textL' which is the left text area of the program. If you run the program, it should show a main panel with two text area on each side. I just need words to be sent to the left text area when the 'Submit' or 'Reset' button is clicked. I'm just trying to test out the JText to make sure it works. I've tried coding it myself in the AcitionPerform method, but had no luck. What I have tested was calling my 'text'(JText variable) and having it setText("asdf") when 'button' is clicked, there's not output into the text area.
All help is greatly appreciated.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
// Your Class
public class Boggle extends JPanel implements ActionListener {
     public final static int NUM_ROWS_COLUMNS = 5;
     private JButton reset;
     private JButton submit;//submit
     //     private JButton clrwrd;
     private JButton arrayofButtons[][] = new JButton[NUM_ROWS_COLUMNS][NUM_ROWS_COLUMNS];
     private JLabel status;
     private JLabel messStatus;
     private JTextArea textL;
     private JTextArea textR;
     private JButton prevButton;
     private int prevRow, prevCol;
     private Lexicon lex = new Lexicon("ENABL.txt");
     // Your Constructor
     public Boggle() {
          BoxLayout ourLayout = new BoxLayout(this, BoxLayout.X_AXIS);
          setLayout(ourLayout);
          JScrollPane scrollLeft = new JScrollPane(buildTextAreaLeft());          
          scrollLeft.setVerticalScrollBar(scrollLeft.createVerticalScrollBar());
          scrollLeft.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
          JPanel MainAreaPanel = new JPanel();
          MainAreaPanel.setLayout(new BoxLayout(MainAreaPanel, BoxLayout.Y_AXIS));
          //                    MainAreaPanel.setPreferredSize(new Dimension(1000, 1000));
          add(scrollLeft);
          add(MainAreaPanel);
          JScrollPane scrollRight = new JScrollPane(buildTextAreaRight());
          scrollRight.setVerticalScrollBar(scrollRight.createVerticalScrollBar());
          scrollRight.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);          
          add(scrollRight);          
          MainAreaPanel.add(buildMainPanel());
          MainAreaPanel.add(buildControlPanel());
          MainAreaPanel.add(buildMessagePanel());
     //Right JTextArea
     private JTextArea buildTextAreaRight(){     
          JTextArea textR = new JTextArea();
          textR = new JTextArea();
          textR.setPreferredSize(new Dimension(300,200));
          textR.setBorder(BorderFactory.createLineBorder(Color.black));
          textR.setLineWrap(true);
          textR.setEditable(true);
          return textR;
     //Left JTextArea
     private JTextArea buildTextAreaLeft(){     
          JTextArea textL = new JTextArea();
          textL= new JTextArea();
          textL.setPreferredSize(new Dimension(300,200));
          textL.setBorder(BorderFactory.createLineBorder(Color.black));
          textL.setLineWrap(true);
          textL.setEditable(true);
          return textL;
     // Your MainPanel
     private JPanel buildMainPanel() {
          JPanel panel = new JPanel();
          GridLayout gridLayout = new GridLayout(0, NUM_ROWS_COLUMNS);
          panel.setLayout(gridLayout);
          for (int row = 0; row < arrayofButtons.length; ++row)
               for (int column = 0; column < arrayofButtons[0].length; ++column) {
                    char letters = (char)(Math.random()*26+65);
                    //                    System.out.println(letters + 0);
                    arrayofButtons[row][column] = new JButton();
                    arrayofButtons[row][column].setBackground(Color.white);
                    arrayofButtons[row][column].setText(letters+"");// Set your letters
                    // in boxes.
                    arrayofButtons[row][column].setPreferredSize(new Dimension(100, 100));
                    arrayofButtons[row][column].addActionListener(this);
                    // Use actionCommand to store x,y location of button
                    arrayofButtons[row][column].setActionCommand(Integer.toString(row)+ " " + Integer.toString(column));
                    panel.add(arrayofButtons[row][column]);
          //          JTextArea textA = new JTextArea();
          //          panel.add(textA);
          //          BoxLayout ourLayout = new BoxLayout(textA, BoxLayout.X_AXIS);
          //          textA.setLayout(ourLayout);
          //          textA.setPreferredSize(new Dimension (100, 50));
          return panel;
      * Called when user clicks buttons with ActionListeners.
     public void actionPerformed(ActionEvent e) {
          JButton button = (JButton) e.getSource();
          if (button == reset){
               status.setText("");
               for (int row = 0; row < arrayofButtons.length; ++row)
                    for (int column = 0; column < arrayofButtons[0].length; ++column){
                         char letters = (char)(Math.random()*26+65);
                         arrayofButtons[row][column].setText(letters+"");
                         arrayofButtons[row][column].setBackground(Color.white);
                         prevButton = null;
                         messStatus.setText("");
          else if (button == submit){
               boolean b = lex.contains(status.getText());
               //               System.out.println(lex); // checking what came in.
               if (b==true){
                    messStatus.setText("'" + status.getText() + "'" + " found. ");
                    status.setText("");
                    textL.setText(status.getText());
                    for (int row = 0; row < arrayofButtons.length; ++row)
                         for (int column = 0; column < arrayofButtons[0].length; ++column){                                   
                              arrayofButtons[row][column].setBackground(Color.white);
                              prevButton = null;
               if (b!=true){
                    messStatus.setText("'" + status.getText() + "'" + " not found. ");
                    status.setText("");
                    for (int row = 0; row < arrayofButtons.length; ++row)
                         for (int column = 0; column < arrayofButtons[0].length; ++column){                                   
                              arrayofButtons[row][column].setBackground(Color.white);
                              prevButton = null;
          else {
               String rowColumn[] = button.getActionCommand().split(" ");
               int row = Integer.parseInt(rowColumn[0]);
               int column = Integer.parseInt(rowColumn[1]);
               if(prevButton == null){
                    prevButton = button;
                    prevRow = row;
                    prevCol = column;
                    arrayofButtons[row][column].setBackground(Color.orange);
                    status.setText(status.getText()+ arrayofButtons[row][column].getText());
               else{
                    int dist = (int)Math.pow((prevRow - row)*(prevRow - row) + (prevCol - column)*(prevCol - column),0.5);
                    if(dist == 1 && button.getBackground() == Color.white ){
                         prevButton.setBackground(Color.green);
                         arrayofButtons[row][column].setBackground(Color.orange);
                         status.setText(status.getText()+ arrayofButtons[row][column].getText());
                         prevButton = button;
                         prevRow = row;
                         prevCol = column;
                * when submit button is clicked, grab status and place in messStatus
     // Your Control Panel
     private JPanel buildControlPanel() {
          JPanel panel = new JPanel();
          BoxLayout ourLayout = new BoxLayout(panel, BoxLayout.X_AXIS);
          panel.setLayout(ourLayout);
          //Your reset button
          reset = new JButton("Reset");
          reset.addActionListener(this);
          panel.add(reset);
          //distance of status from Reset button
          JPanel space = new JPanel();
          space.setPreferredSize(new Dimension (10,10));
          panel.add(space);
          //Your status label
          status = new JLabel();
          panel.add(status);
          //the distance from Reset button to Submit button
          JPanel blank = new JPanel();
          blank.setPreferredSize(new Dimension(400, 30));
          panel.add(blank);
          //your Submit button
          submit= new JButton("SUMBIT");
          submit.addActionListener(this);
          panel.add(submit);
          //button panel
          panel.add(Box.createHorizontalGlue());
          JLabel statusLabel = new JLabel();
          panel.add(statusLabel);
          panel.setBorder(BorderFactory.createLineBorder(Color.black));
          return panel;
     private JPanel buildMessagePanel(){
          JPanel messPanel = new JPanel();
          BoxLayout ourLayout = new BoxLayout(messPanel, BoxLayout.X_AXIS);
          messPanel.setLayout(ourLayout);
          messPanel.setPreferredSize(new Dimension(100,50));
          messStatus = new JLabel();
          messPanel.add(messStatus);
          return messPanel;
     // create and show GUI
     private static void createAndShowGUI() {
          // Create and set up the window.
          JFrame frame = new JFrame("BoggleUI");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          // Add contents to the window.
          frame.add(new Boggle());
          // Display the window.
          frame.pack();
          frame.setVisible(true);
     public static void main(String[] args) {
          // Schedule a job for the event-dispatching thread:
          // creating and showing this application's GUI.
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    createAndShowGUI();
}Edited by: user13813121 on Mar 22, 2011 8:39 AM

I found this code, which is not so different from mine, but a lot simpler easier to understand. I just don't know how this code works even without implementing the Policies for JScroll.
import java.awt.*;
import javax.swing.*;
public class scrollDemo extends JFrame {
    //============================================== instance variables
   JTextArea _resultArea = new JTextArea(6, 20);
    //====================================================== constructor
    public scrollDemo() {
        //... Set textarea's initial text, scrolling, and border.
        _resultArea.setText("Enter more text to see scrollbars");
        _resultArea.setLineWrap(true);
        JScrollPane scrollingArea = new JScrollPane(_resultArea);
        //... Get the content pane, set layout, add to center
        JPanel content = new JPanel();
        content.setLayout(new BorderLayout());
        content.add(scrollingArea, BorderLayout.CENTER);
        //... Set window characteristics.
        this.setContentPane(content);
        this.setTitle("TextAreaDemo B");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.pack();
    //============================================================= main
    public static void main(String[] args) {
        JFrame win = new scrollDemo();
        win.setVisible(true);
}

Similar Messages

  • How to log into Mountain Lion if the FileVault user can't unlock the drive?

    I have a computer that has the FileVault user not able to decrypt the drive. I've read on how to get into the machine and have successfully done so a few times. This has been accomplished by creating a new Admin user, deleting the original user, recreating it as a clean new user. Each time I give the computer back to the owner and he tries to restore from a backup. The problem is, he restores and it creates the same problem.
    The most recent time he did this, I could not for the life of me figure out how to create a new user. When I try to log in as the FileVault user I get the "unable to log into filevault user account at this time" error.
    The only way I could figure out how to get another admin user created so that I could delete his user was to reinstall the OS. Is that the only way this can be done?

    I don't think Verizon will release the username and password to the camera administration to prevent people from doing what you want to do.
    Even if you have the username / password, I would imagine there is a hefty equipment charge if you don't return the camera, which will make it cheaper to just buy a camera in retail stores.

  • Alter a BAPI Result Table, how to get into the display "loop" ?

    Hello all,
    i have a problem regarding the result rows of a RFC/BAPI Call.
    There are three views, let's say 1,2,3. In View 1, i call a BAPI, and display the results in a table in View 2. I added a button in each row, which calls View 3 and displays some details concerning the selected row.
    I now want to store a flag for each row, that has been displayed in this way.
    In View 3 i store the key value of the displayed row in an own value node in the context.
    When i go back from View 3 to View 2, i want to see that flag (in an extra column) in every row, that has been selected in this session.
    So i do not know, how to alter a single row in the BAPI result table, how to get into the "loop" that is used by WD to display the table.
    already tried a supply function, but i was not able to alter single rows.
    Any suggestions/tips or perhaps code fragments of working supply functions ?
    Thank you !

    Hello,
    I'm not sure whether I understood your problem correctly, but I will try to give an answer.
    The easiest way I see is to copy the RFC Results to a Component Controller Context structure with an additional Flag field. You can use WDCopyService for copying.
    Then on the event of selecting you set your flag as appropriate for you (e.g. if you want to use an image as flag you set the Image path) on the current element of your table. Then display View 3.
    On going back View 2 should show now the new flag values...
    The trick is to copy the values (as at Time structures can not be expandend with new fields) and set the Flag on the onSelect event.
    Hope this helps,
    Frank

  • How to go into a function module through SE80 t - code

    Hi All , 
                 How to go into a function module through SE80 t - code.
    Thanks in advance.

    >
    Balaji Krishnamoorthy wrote:
    > Hi All , 
    >              How to go into a function module through SE80 t - code.
    >
    > Thanks in advance.
    Hi,
    With  help of  function group
    Thanks & Regards
    Edited by: Always Learner on Oct 16, 2008 2:31 PM

  • How to get into my iPhone5 if I have forgotten my password, How to get into my iPhone5 if I have forgotten my password

    How to get into my phone if I forgot my password

    LOST PASSCODE
    You should be able to remove the passcode by restoring the device.
    Connect the device to the computer with which you normally sync and open iTunes.
    Note: If iTunes prompts you to enter the passcode, try another computer that you have synced with. Otherwise, go to "If you have never synced your device with iTunes", below.
    Right-click the device in the left column and select Back up.
    When the backup is complete, select Restore.
    When finished, restore from your most recent backup.
    Otherwise read this
    If that doesn’t work  you will need to perform a factory restore to remove it. Or read:
    Enter Wrong passcode
    http://support.apple.com/kb/ht1212

  • How to get into BIOS in Windows 8

    my question is this will the same fan control software that was on windows seven 64 bit lenova work with windows 8 and 8.1 just wondering if i have to uninstall before i upgrade or will it be compatable with 8 and 8.1 upgrade hope someone can steer me in the right direction here it would be appreciated-thanks

    Hi,
    follow the links below:
    http://forums.lenovo.com/t5/Windows-8-and-8-1-Know​ledge-Base/How-to-get-into-BIOS-in-Windows-8/ta-p/​...
    http://support.lenovo.com/en_US/detail.page?DocID=​HT076607
    win8 should be installed on the big HDD.
    If you have enough computing skills Win8.1 Update could be installed on the small SSD using the new feature - WimBOOT.
    x220 | i5-2520m | Intel ssd 320 series | Gobi 2000 3G GPS | WiFi
    x220 | i5-2520m | hdd 320 | Intel msata ssd 310 series | 3G GPS | WiFi
    Do it well, worse becomes itself
    Русскоязычное Сообщество   English Community   Deutsche Community   Comunidad en Español

  • How to insert into more than one table at a time also..

    hi,
    i am a newbee.
    how to insert into more than one table at a time
    also
    how to get a autoincremented value of an id say transactionid for a particular accountid.
    pls assume table as
    transactionid accountid
    101 50
    102 30
    103 50
    104 35
    i want 102 for accountid 30 and 103 for accountid 50.
    thank u

    @blushadow,
    You can only insert into one table at a time. Take a look here :
    Re: insert into 2 tables
    @Raja,
    I want how to extract the last incremented value not to insert.Also, I don't understand your thread title... which was "how to insert into more than one table at a time also.. "
    Insert, extract... ? Can you clarify your job ?
    Nicolas.

  • How to insert into a table with a nested table which refer to another table

    Hello everybody,
    As the title of this thread might not be very understandable, I'm going to explain it :
    In a context of a library, I have an object table about Book, and an object table about Subscriber.
    In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
    And finally, this nested table refers to the Book table.
    Here the code concerning the creation of theses tables :
    Book :
    create or replace type TBook as object
    number int,
    title varchar2(50)
    Loan :
    create or replace type TLoan as object
    book ref TBook,
    loaning_date date
    create or replace type NTLoan as table of TLoan;
    Subscriber :
    create or replace type TSubscriber as object
    sub_id int,
    name varchar2(25)
    loans NTLoan
    Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
    insert into OSubscriber values
    *(1, 'LEVEQUE', NTLoan(*
    select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
    Of course, there is an occurrence of book in the table OBook with the number attribute 1.
    Oracle returned me this error :
    SQL error : ORA-00936: missing expression
    00936. 00000 - "missing expression"
    Thank you for your help

    1) NUMBER is a reserved word - you can't use it as identifier:
    SQL> create or replace type TBook as object
      2  (
      3  number int,
      4  title varchar2(50)
      5  );
      6  /
    Warning: Type created with compilation errors.
    SQL> show err
    Errors for TYPE TBOOK:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
    SQL> create table OSubscriber of TSubscriber
      2  nested table loans store as loans
      3  /
    Table created.
    SQL> create table OBook of TBook
      2  /
    Table created.
    SQL> insert
      2    into OBook
      3    values(
      4           1,
      5           'No Title'
      6          )
      7  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> insert into OSubscriber
      2    values(
      3           1,
      4           'LEVEQUE',
      5           NTLoan(
      6                  (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
      7                 )
      8          )
      9  /
    1 row created.
    SQL> select  *
      2    from  OSubscriber
      3  /
        SUB_ID NAME
    LOANS(BOOK, LOANING_DATE)
             1 LEVEQUE
    NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
    SQL> SY.

  • How do I log into my iCloud account. I have iCloud installed on my iPad but can not figure out how to log into my iCloud account to restore a message

    How do I log into my iCloud account. I have iCloud installed on my iPad but can not figure out how to log into my iCloud account to restore a message

    Settings / iCloud on the iOS device to view your settings and options.
    Storage & Backup / iCloud Backup is how you restore the device with your last backup.

  • My iPhone was stolen.  How do I retrieve the pictures etc that were on imt.  I know they must be in the iCloud but I don't know how to get into it from my iPad.  Also, I would like to try to locate the phone ...how do I do that from my iPad?

    My iPhone was stolen.  How do I retrieve the pictures etc that were on imt.  I know they must be in the iCloud but I don't know how to get into it from my iPad.  Also, I would like to try to locate the phone ...how do I do that from my iPad?

    These links may be helpful.
    How to Track and Report Stolen iPad
    http://www.ipadastic.com/tutorials/how-to-track-and-report-stolen-ipad
    Reporting a lost or stolen Apple product
    http://support.apple.com/kb/ht2526
    Report Stolen iPad Tips and iPad Theft Prevention
    http://www.stolen-property.com/report-stolen-ipad.php
    How to Find a Stolen iPad
    http://www.ehow.com/how_7586429_stolen-ipad.html
    Oops! iForgot My New iPad On the Plane; Now What?
    http://online.wsj.com/article/SB10001424052702303459004577362194012634000.html
     Cheers, Tom

  • I would like to know how do I install the brazilian keyboard into macbook air, keyboard with accents (Portuguese Language), I tried so many times how to put into it (Macbook Air). So, thanks for now! I'm waiting for it.

    I would like to know how do I install the brazilian keyboard into macbook air, keyboard with accents (Portuguese Language), I tried so many times how to put into it (Macbook Air). So, thanks for now! I'm waiting for it.

    After you go to system preferences/keyboard/input sources as suggested by sberman, click on the + button and scroll down to Portuguese and select that.  Over at the right you will see the choices Brazilian, Brazilian abnt, Portuguese.  You might want to add all three to see which you like best.
    The "Brazilian" layout is pretty useless.  It is identical to the US layout and the only way to make accents is via the option key shortcuts:  option + n, then o gives you õ.
    The Brazilian abnt and Portuguese layouts have dead keys for adding accents over at the right edge of the keyboard.  But these may not match what is printed on your keys.
    You may prefer to stay with the US layout.  On that you can get accented letters by just holding down the base letter and selecting what you want from the popup menu that appears.  Or you can use the option key shortcuts.
    Another option is the layout called US International PC, which has accent deadkeys on ~, ', etc.
    Which ever layout you want to use, you must select it in the "flag" menu at the top right of the screen.
    To see which key does what for any layout, use the Keyboard Viewer:
    http://support.apple.com/kb/PH13746

  • How to switch into an international keyboard?

    How to switch into international keyboard while I am using the apple's wireless keyboard?
    You know when u connect the wireless keyboard on ipad, the original keyboard on the ipad screen will disappear. at that time, how can i switch the english keyboard to an international keyboard. (by the way, in my ipad another keyboard is enabled.)
    Thx a lot in advance.

    i got my own answer
    press the "command" then "space" button, then screen will show the international keyboard to choose. using the "space" to choose and confirm.
    btw. the wireless keyboard is awesome!

  • Quick doubt.. from cursor vairable how to get into page vairable

    Hello
    i am creating an apex page where i have 2 regions. From the Top region stores all fields entered into the bottom region
    Text fields like first name and last name and address fields are in region 2(bottom).After region 2, i have a add person button.
    Once i click add person, that person will get into top i.e region 1.
    Now, Region 1 got person1 first name ,last name
    person2, first name,last name
    etc..
    I am not able to display like p1_first_name,p1_laast_name as the list is not stable..it is growing and not showing the person who already got saved..I can retrieve them from DB using a cursor..But from cursor vairable how to get into page vairable..
    appreciate ur help..
    kp

    Your explanation is not good enough. You have to make a better description of your problem or create an example at apex.oracle.com.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • HELP!!!!!! - How to write into a file?

    How to write into a file?
    I want to make a script that will connect(not enter) to my website[for example, www.vasa.com] every time i connect to the internet.
    Now i have 3 problems:
    1. i dont know how to write into a file
    2. i dont know how to make it connect to my 'server' without entering the website
    3. i dont know what file to write it to
    so if someone can help me, please do.

    Well, how about RTFM?? In this case that can be found here:
    http://developer.java.sun.com/developer/onlineTraining/
    BTW - these things have been asked azillion times, search the forum.

  • How to eneter into editing mode on ListView ?

    Hello everyone
    ListView has setEditable() method and several editing-related properties onEditCancelProperty(), onEditCommitProperty() and onEditStartProperty() .
    How to eneter into editing mode on ListView ?
    What operation is needed ?
    Best regards.

    Hi,
    I just posted a question related to editing in this thread today. It has some source code that may help you:
    ListView.edit(index i) invokes canceEdit
    --Toni                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for