Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help for applet

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help for applet

    Sorry for my bad english....
    This applet adds the label each time you restart, because it is rerun the start method.

    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.BorderFactory;
    import java.awt.GridLayout;
    import java.awt.Color;
    import java.awt.Font;
     
    public class Example extends JApplet {
      private JLabel label1;
      private JLabel label2;
      private JLabel label3;
     
      class Etichetta extends JLabel {
        Etichetta (String nomeFont, int dim, Color fg, Color bc) {
          super("Ehiiiii!");
          setHorizontalAlignment(JLabel.CENTER);
          setForeground(fg);
          setFont(new Font(nomeFont, Font.BOLD, dim));
          setBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, bc));
        }
      }
     
      public void init() {
        label1 = new Etichetta("Courier", 48, Color.blue, Color.yellow);
        label2 = new Etichetta("Verdana", 36, Color.yellow, Color.red);
        label3 = new Etichetta("Times New Roman", 60, Color.red, Color.blue);
      }
     
      public void start() {
        getContentPane().setLayout(new GridLayout(3, 1, 5, 5));
        getContentPane().setBackground(Color.green);
        getContentPane().add(label1);
        getContentPane().add(label2);
        getContentPane().add(label3);
      }
    }

    The method should be changed to "inform" to add them only when you first start.
    But I can not find the way ....
    Last edited by wrapper; September 14th, 2014 at 04:36 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,487
    Thanks
    53
    Thanked 2,407 Times in 2,360 Posts

    Default Re: help for applet

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    See the tutorial: http://docs.oracle.com/javase/tutori...let/index.html
    Especially this part: http://docs.oracle.com/javase/tutori...etMethods.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: August 16th, 2013, 03:25 PM
  2. Replies: 3
    Last Post: July 3rd, 2013, 08:25 AM
  3. Replies: 1
    Last Post: May 7th, 2013, 07:49 AM
  4. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  5. Replies: 0
    Last Post: October 13th, 2011, 07:42 PM