2 Replies - 1062 Views - Last Post: 04 April 2012 - 02:21 PM Rate Topic: -----

#1 kirubreezy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 02-April 12

Creating a Simple Text Editor - Panel Created will not Comple

Posted 04 April 2012 - 02:02 PM

I am creating a simple text editor through a series of panels...

First I created a menu panel

//********************************************************************
//  BoxPanel.java       Authors: Lewis/Loftus
//
//  Represents the panel in the LayoutDemo program that demonstrates
//  the box layout manager.
//********************************************************************

import java.awt.*;
import javax.swing.*;

public class MenuPanel extends JPanel
{
   //-----------------------------------------------------------------
   //  Sets up this panel with some buttons to show how a vertical
   //  box layout (and invisible components) affects their position.
   //-----------------------------------------------------------------
   public MenuPanel()
   {
      setLayout (new BoxLayout (this, BoxLayout.X_AXIS));
      // this is the current object, which is this BoxPanel object
      // in order to work, the BoxLayout needs to access the BoxPanel object

      setBackground (Color.green);

      JButton b1 = new JButton ("BUTTON 1");
      JButton b2 = new JButton ("BUTTON 2");
      JButton b3 = new JButton ("BUTTON 3");
      JButton b4 = new JButton ("BUTTON 4");
      JButton b5 = new JButton ("BUTTON 5");


      add (b1);  
      add (Box.createRigidArea (new Dimension (0, 10)));
      add (b2);
      add (Box.createVerticalGlue()); /// allow the area between b2 and b3 to stretch
      add (b3);
      add (Box.createHorizontalGlue()); /// allow the area between b2 and b3 to stretch
      add (b4);
      add (Box.createRigidArea (new Dimension (10, 20)));
      add (b5);
      
      JRadioButton b6 = new JRadioButton("Small Font");
      JRadioButton b7 = new JRadioButton("Medium Font");
      JRadioButton b8 = new JRadioButton("Large Font");
      
      add(b6);
      add(b7);
      add(b8);
      
      JTextArea myTextArea = new JTextArea();
      
      add(myTextArea);
      
      add(bp);
   }
}



Then I created an Editor Panel

import java.awt.*;
import javax.swing.*;

public class EditorPanel extends JPanel
{
   //-----------------------------------------------------------------
   //  Sets up this panel with a button in each area of a border
   //  layout to show how it affects their position, shape, and size.
   //-----------------------------------------------------------------
   public EditorPanel()
   {
      setLayout (new BorderLayout());

      setBackground (Color.green);

      JButton b1 = new JButton ("BUTTON 1");
      JButton b2 = new JButton ("BUTTON 2");
      JButton b3 = new JButton ("BUTTON 3");
      JButton b4 = new JButton ("BUTTON 4");
      JButton b5 = new JButton ("BUTTON 5");
      MenuPanel mp = new MenuPanel();
      

      // add (b1, BorderLayout.CENTER);
      JTextArea editArea = new JTextArea();
      JTextArea myTextArea = new JTextArea();
      editArea.setFont (new Font ("Times", Font.PLAIN, 24));
      add (editArea, BorderLayout.CENTER);
      add (myTextArea, BorderLayout.CENTER);
      b3.setFont (new Font ("Times", Font.PLAIN, 24));
      
      add (b2, BorderLayout.NORTH);
      add (b3, BorderLayout.SOUTH);
      add (b4, BorderLayout.EAST);
      // add (b5, BorderLayout.WEST);
      
      add (mp, BorderLayout.NORTH);
   }
}


I am now try to created an Editors Lab of Sorts, A Display...so It has an intro Panel (as a tab) and an Editor's Panel which stores the Panel it creates in a variable that I can pass to my Menu Panel...

I have this....but it is not compiling and I am unsure of how to proceed

import java.awt.*;
import javax.swing.*;

public class EditorPanel extends JPanel
{
   //-----------------------------------------------------------------
   //  Sets up this panel with a button in each area of a border
   //  layout to show how it affects their position, shape, and size.
   //-----------------------------------------------------------------
   public EditorPanel()
   {
      setLayout (new BorderLayout());

      setBackground (Color.green);

      JButton b1 = new JButton ("BUTTON 1");
      JButton b2 = new JButton ("BUTTON 2");
      JButton b3 = new JButton ("BUTTON 3");
      JButton b4 = new JButton ("BUTTON 4");
      JButton b5 = new JButton ("BUTTON 5");
      MenuPanel mp = new MenuPanel();
      

      // add (b1, BorderLayout.CENTER);
      JTextArea editArea = new JTextArea();
      JTextArea myTextArea = new JTextArea();
      editArea.setFont (new Font ("Times", Font.PLAIN, 24));
      add (editArea, BorderLayout.CENTER);
      add (myTextArea, BorderLayout.CENTER);
      b3.setFont (new Font ("Times", Font.PLAIN, 24));
      
      add (b2, BorderLayout.NORTH);
      add (b3, BorderLayout.SOUTH);
      add (b4, BorderLayout.EAST);
      // add (b5, BorderLayout.WEST);
      
      add (mp, BorderLayout.NORTH);
   }
}


If anyone can Help it would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a Simple Text Editor - Panel Created will not Comple

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Creating a Simple Text Editor - Panel Created will not Comple

Posted 04 April 2012 - 02:20 PM

A quick one, I have to go take my train,
     add (editArea, BorderLayout.CENTER);  
     add (myTextArea, BorderLayout.CENTER);  


each of the 5 areas of a BorderLayout can have only 1 component
Here you add editArea CENTER
then you add myTextArea CENTER, it will go there but will remove editArea from that region

And if it is not compiling: post yours errors !!!
We can probably fix them just by looking at them, no need to read your code line per line trying to figure out if the syntax is correct or not. This is the compiler job.
Was This Post Helpful? 0
  • +
  • -

#3 kirubreezy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 02-April 12

Re: Creating a Simple Text Editor - Panel Created will not Comple

Posted 04 April 2012 - 02:21 PM

Okay. Will try.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1