By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,161 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,161 IT Pros & Developers. It's quick & easy.

Why doesn't my JTextArea appear in my JApplet?

P: 1
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
Share this Question
Share on Google+
3 Replies


Expert 10K+
P: 11,448
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
Expert 100+
P: 1,216
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
Expert 100+
P: 1,216
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

Post your reply

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