Results 1 to 5 of 5
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Applet, To center text and To open I engage in a dialog in an Applet

    1) I have a figure (for example, an ellipse) I must draw it with a text inside that it has to be trim.
    If you don't understand imagine a diagram of states,in where each state has a name. How can I center the text?
    Now I'm calculating the High/width of the figure and then I center it the problem is when there are more than one line

    2) I want to open modal Dialogo, but I cannot create it because the constructor requests to me that the owner is a Frame or a Dialog and what I have is an Applet.

    Some idea?

    Marcus:cool:

  2. #2
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    With respect to the trim there is layout that is called borderlayout that divides the screen to you in north, south, east, west and to center

    2: Applet extends of Panel who extends of Frame Container extends of Window that extends of Container ergo you cast to your Applet to Container, you send it and then if you want you can use as container or return to cast it

    Daniel

  3. #3
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default

    How can I center the text within the figure? I use it with the Applet to locate the bar of tools and the Canvas,
    but i don' know how can I do to the figure, can you send me some code?

    I did not prove what you said to me, but it does not seem to me a very elegant solution, in addition I do not believe that it works, because the Dialog() waits for a Frame or a Dialog, not a container, that is to say, it is necessary to see if the constructor uses the own methods of Frame or Dialog…

    This is one of the bad ones of which Java is typed… (This in Smalltalk does not happen). I already solved it, simply I put the applet in an instance variable of a Frame, and what I do in the constructor of the Frame he is init(); start(); to the applet.

    Eric

  4. #4
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default RE: Applet, To center text and To open I engage in a dialog in an Applet

    Here is an example of applet
    about the part 2 that you describe, I dont understand, send the code maybe I can help you.

    greetings

    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    
    public class AWT extends Applet {
       public void init() {
         setLayout(new BorderLayout());
         add(new Button("North"), BorderLayout.NORTH);
         add(new Button("South"), BorderLayout.SOUTH);
         add(new Button("East"), BorderLayout.EAST);
         add(new Button("West"), BorderLayout.WEST);
         add(new Button("Center"), BorderLayout.CENTER);
       }
    }
    Felissa:p

  5. #5
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default RE: Applet, To center text and To open I engage in a dialog in an Applet

    That example I understand it… but setLayout() is a message of Applet. I need to center the text inside of a circle (or any other figure). How can I apply the Layout to a figure? Is there some method in Graphics2D that helps me to center the text? With respect to the solution that I found, and it implements was this:

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    class FrameLine extends Frame {
    private AppletDiagonal oneApplet; // One will be
    public static void main( String[] s ) {
    new FrameLine( 200, 230 );
    }
    public FrameLine( int wide, int length ) {
    super(); // Constructor of Component
    // A listener adds itself who closed the application
    addWindowListener( new ListenerLine() );
    // A diagonal applet is created
    oneApplet=new AppletDiagonal();
    oneApplet.init();
    oneApplet.start();
    // The applet in frame puts
    add( oneApplet );
    setSize(wide,length); // it fits frame
    setVisible(true); // it shows frame
    }
    // Nested class
    class ListenerLine extends WindowAdapter {
    //I rewrite the method of “when window is closed”
    
    public void windowClosing(WindowEvent e) {
    oneApplet.stop();
    oneApplet.destroy();
    System.exit(0);
    }
    }
    }
    Marcus:cool:

Similar Threads

  1. Applet - reading text files packed into JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:15 AM
  2. Replies: 0
    Last Post: 01-21-2008, 01:29 PM
  3. Open "Save Page As" Dialog Box
    By Anubha in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-12-2007, 09:27 PM
  4. First Applet HELP????
    By nvidia in forum New To Java
    Replies: 0
    Last Post: 08-13-2007, 10:11 PM
  5. Applet
    By kapoorje in forum Java Applets
    Replies: 0
    Last Post: 07-24-2007, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •