473,395 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why doesn't my JTextArea appear in my JApplet?

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import javax.swing.event.*;
  5. import java.io.File;
  6. import java.util.*;
  7. /*
  8. <Applet Code="MyPaint.class" width=400 height=400>
  9. </Applet>
  10. */ 
  11. public class MyPaint extends JApplet 
  12. {
  13.     /* Declaring the variables.*/
  14.     JPanel panel;
  15.     JPanel textAreaPanel;
  16.     JTextArea drawTextArea;
  17.     JScrollPane drawScrollPane;
  18.     JLabel line, color, paint,kid,cil;
  19.     JButton circle, rect, poly, ellipse;
  20.     JComboBox cbLine, cbFill;
  21.     GridBagLayout g;
  22.     GridBagConstraints gbc;
  23.     public void init()
  24.     {
  25.         g=new GridBagLayout();  
  26.         gbc=new GridBagConstraints();
  27.         panel= (JPanel)getContentPane();
  28.         panel.setLayout(g);
  29.         paint = new JLabel("My Paint Application");
  30.         gbc.anchor= GridBagConstraints.NORTH;
  31.         gbc.gridx =2;
  32.         gbc.gridy = 0;
  33.         g.setConstraints(paint,gbc);
  34.         panel.add(paint);
  35.         rect = new JButton("Rectangle");
  36.         gbc.ipadx = 2; 
  37.         gbc.ipady = 2;
  38.         gbc.gridy = 1;
  39.         gbc.gridx = 1;
  40.         g.setConstraints(rect,gbc);
  41.         panel.add(rect);
  42.         circle = new JButton("Circle");
  43.         gbc.ipadx = 2;
  44.         gbc.ipady = 2;
  45.         gbc.gridy = 1;
  46.         gbc.gridx = 2;
  47.         g.setConstraints(circle,gbc);
  48.         panel.add(circle);
  49.         poly = new JButton("Polygon");
  50.         gbc.ipadx = 2;
  51.         gbc.ipady = 2;
  52.         gbc.gridy = 1;
  53.         gbc.gridx = 3;
  54.         g.setConstraints(poly,gbc);
  55.         panel.add(poly);
  56.         ellipse = new JButton("Ellipse");
  57.         gbc.ipadx = 2;
  58.         gbc.ipady = 2;
  59.         gbc.gridy = 1;
  60.         gbc.gridx = 4;
  61.         g.setConstraints(ellipse,gbc);
  62.         panel.add(ellipse);
  63.         line = new JLabel("select line color");
  64.         gbc.ipadx = 4;
  65.         gbc.ipady = 4;
  66.         gbc.gridy = 2;
  67.         gbc.gridx = 1;
  68.         g.setConstraints(line,gbc);
  69.         panel.add(line);
  70.         kid = new JLabel("");
  71.         gbc.ipadx = 4;
  72.         gbc.ipady = 4;
  73.         gbc.gridy = 2;
  74.         gbc.gridx = 2;
  75.         g.setConstraints(kid,gbc);
  76.         panel.add(kid);
  77.         color = new JLabel("select Fill color");
  78.         gbc.ipadx = 4;
  79.         gbc.ipady = 4;
  80.         gbc.gridy = 2;
  81.         gbc.gridx = 3;
  82.         g.setConstraints(color,gbc);
  83.         panel.add(color);
  84.         String Line[]={"choose the color","Red","Yellow","Green","Blue","Cyan","Mangeta","Orange"};
  85.         cbLine = new JComboBox(Line);
  86.         gbc.fill= GridBagConstraints.BOTH;
  87.         gbc.insets=new Insets(5,5,5,5);
  88.         gbc.ipadx = 4;
  89.         gbc.ipady = 4;
  90.         gbc.gridy = 3;
  91.         gbc.gridx = 1;
  92.         g.setConstraints(cbLine,gbc);
  93.         panel.add(cbLine);
  94.         cil = new JLabel("");
  95.         gbc.ipadx = 4;
  96.         gbc.ipady = 4;
  97.         gbc.gridy = 3;
  98.         gbc.gridx = 2;
  99.         g.setConstraints(cil,gbc);
  100.         panel.add(cil);
  101.         String Fill[]={"choose the color","Red","Yellow","Green","Blue","Cyan","Mangeta","Orange"};
  102.         cbFill = new JComboBox(Fill);
  103.         gbc.fill= GridBagConstraints.BOTH;
  104.         gbc.insets=new Insets(5,5,5,5);
  105.         gbc.ipadx = 4;
  106.         gbc.ipady = 4;
  107.         gbc.gridy = 3;
  108.         gbc.gridx = 3;
  109.         g.setConstraints(cbFill,gbc);
  110.         panel.add(cbFill);
  111.         textAreaPanel = new JPanel(new GridLayout(2,1,5,5));
  112.         drawTextArea = new JTextArea();
  113.         drawScrollPane = new JScrollPane(drawTextArea);
  114.         textAreaPanel.add(drawScrollPane);
  115.         textAreaPanel.setLayout(g);
  116.         textAreaPanel= (JPanel)getContentPane();
  117.     }
  118.  
  119.     public static void main(String[] args)
  120.     {
  121.         MyPaint mp = new MyPaint();
  122.         mp.setSize(700,500);   
  123.         mp.setVisible(true);
  124.     }
  125. }
  126. kindly,assist me on this codes to make the textarea show?
kindly,assist me on this codes to make the textarea show?
Jan 23 '08 #1
3 2104
JosAH
11,448 Expert 8TB
kindly,assist me on this codes to make the textarea show?
You should add your TextAreaPanel to the content pane of your JApplet.
The last lines of your initialization method are completely wrong.

kind regards,

Jos
Jan 23 '08 #2
BigDaddyLH
1,216 Expert 1GB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Jan 23 '08 #3
BigDaddyLH
1,216 Expert 1GB
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Jan 23 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Eynon | last post by:
I know that the basic methods that can be overwritten for class JApplet are init, and paint. However, the API does not specifically state this, and JApplet does not describe this right away.. How...
1
by: - ions | last post by:
Hello, i am relatively new to programming, Java being the first language im learning. At the moment im having trouble changing the setEnable value of a button, relative to the state of a JTextArea,...
0
by: Kookymon1 | last post by:
This is an attempt to respond to an older question (several months). Date: 2002-03-07 13:10:23 PST Subject: On the Common DOM API and Applets. The original message was: >LiveConnect and the...
1
by: Chris Williams | last post by:
I haven't done any Java programming for a good long bit, so this is probably something really silly but anyways, can anyone tell me why my JTextArea is not appearing when I run this? public...
2
by: Aurel | last post by:
Hi, I developped an applet (JApplet class) and now I'd like to integrate it in another application which is a JFrame one... Does anyone can help ? Thanks in advance... AureL
1
by: Colibasi | last post by:
I would like to have a JTextArea with a background white and text should be readonly. The way I tried is something like this: JTextArea text = new JTextArea(); text.setEditable(false);...
1
by: - | last post by:
I have googled and learned that there are limitations with JApplet writing to files on remote host. However, I am unsure as to whether it is possible to do so on the same computer. Please advice....
5
by: James Barrett | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I am experimenting with JApplet and JPanel. My JApplet contains a JPanel called jpanel1 size 210x210. I created a class myPanel which...
1
by: chanshaw | last post by:
Ok my problem is that when it loads the JTextArea, it does not show the full component's width and height. I've tried specifying it with setrow, setcolumn, setprefferedsize, all of that. It does...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.