13 Replies - 993 Views - Last Post: 05 July 2010 - 04:13 PM Rate Topic: -----

#1 jaythewebripper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 17-June 10

Java Applets

Posted 24 June 2010 - 10:57 AM

hey some1 please do let me know how do I create frames in a Java Applet window...

I want to partition the applet window into 2 like the way we do in an HTML page...

help me please...!
Is This A Good Question/Topic? -1
  • +

Replies To: Java Applets

#2 jaythewebripper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 17-June 10

Re: Java Applets

Posted 24 June 2010 - 10:59 AM

hey some1 please do let me know how do I create frames in a Java Applet window...

I want to partition the applet window into 2 like the way we do in an HTML page...

help me please...!
Was This Post Helpful? -2
  • +
  • -

#3 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Java Applets

Posted 24 June 2010 - 11:01 AM

If you wanted to use JFrames (Swing), I suggest you look into JApplets. The API is here This works almost the same as the JFrame, but it is geared towards applets

if you wanted to go the Applet (AWT) route, you don't use frames, you use an init(constructor-like), start(main()-like), stop, and destroy methods

This post has been edited by Luckless: 24 June 2010 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,465
  • Joined: 27-December 08

Re: Java Applets

Posted 24 June 2010 - 11:42 AM

@Luckless: Actually, with either JApplet or Applet, you have to override the init() method.

@jaythewebripper: I think what you'll want to use is BorderLayout.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,204
  • Joined: 20-September 08

Re: Java Applets

Posted 24 June 2010 - 11:51 AM

Use a JSplitPane

http://java.sun.com/.../splitpane.html
Was This Post Helpful? 0
  • +
  • -

#6 ts230  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 225
  • Joined: 11-July 09

Re: Java Applets

Posted 24 June 2010 - 12:12 PM

Yeah, use a JSplitPane, BorderLayout, or just make two separate Applets. Definitely use Swing for the Applet so you can theme it to look like the rest of the WebPage too, and AWT only has a few components that you can use. If you need access to the File System and some other things, consider making a WebStart Application or a simple JAR file that users can launch,
Was This Post Helpful? 0
  • +
  • -

#7 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Java Applets

Posted 24 June 2010 - 12:39 PM

Thanks for the correction Mac, I should've looked a little more into JApplet. I don't usually use it
Was This Post Helpful? 0
  • +
  • -

#8 jaythewebripper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 17-June 10

Re: Java Applets

Posted 04 July 2010 - 06:54 AM

hey sm1 please do let me know how do I get rid of the flicker that is introduced in my Applet when I animate it with the call to repaint() method...!
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,465
  • Joined: 27-December 08

Re: Java Applets

Posted 04 July 2010 - 08:37 AM

Take a look at using Swing Timer to repaint() every x milliseconds, like I've done below. Just make sure you start your Timer.

Timer t = new Timer(20, new ActionListener(){
   public void actionPerformed(ActionEvent e){
        repaint();
   }
});


Was This Post Helpful? 0
  • +
  • -

#10 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Java Applets

Posted 04 July 2010 - 01:11 PM

The flicker you are experiencing is because your image is being painted straight to the frame. You are going to want to look into double buffering your image (Which is a technique where you paint your image to an offscreen image THEN update the applet)
Was This Post Helpful? 1
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,465
  • Joined: 27-December 08

Re: Java Applets

Posted 04 July 2010 - 02:46 PM

Can you show us your code? Right now, we are guessing at the problem. If you show us your code, we can better help. :)

If you choose the double-buffering route, you might want to look at using a BufferedImage.
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

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

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

Re: Java Applets

Posted 04 July 2010 - 05:32 PM

We are the blinds leading the blinds here

You haven't post any code yet
May be a GridLayout(1,2) will do the job

DoubleBuffering is required on rare cases

So post the offending code and then we'll see
Was This Post Helpful? 0
  • +
  • -

#13 jaythewebripper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 17-June 10

Re: Java Applets

Posted 05 July 2010 - 09:24 AM

actually the code I have written is not so good...!

but anyways I can post it here coz I ma dismiss this code and write the new one coz I lacked planning in creating this applet...!




/**
 <applet code='Turing_Machine.class' width='1200' height='400'>
 </applet>
 */

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.net.*;


public class Parallel_Processing extends Applet implements ActionListener
{
   Image oscar_image;
   String s1;
   Color authColor, titleColor;
   int Xpostion=400, Ypostion=400;
   TextField t1 = new TextField(15);
   Point p= new Point(450,450);

   public Parallel_Processing()
   {

   t1.setLocation(p);
   add(t1);
   t1.addActionListener(this);
   
   }

    public void actionPerformed(ActionEvent event)
    {
        String s = t1.getText();
        String sUp = s.toUpperCase();
        t1.setText(sUp);
    }
   

    public void init()
    {
        setSize(1000,604);          // set the size of the Applet
   
        oscar_image=getImage(getCodeBase(),"oscar4.jpg");
          authColor= new Color(68,68,68);
          titleColor= new Color(0,0,0);
          
        }

    public class block
    {
               int y_coord;

        void drawblock(Graphics g, int blk_no, Color blk_color)
        {
     
            y_coord=100+(25*(blk_no-1));

            g.setColor(Color.BLACK);
            g.drawRect(349, y_coord-1, 21, 21);         //draw borders for the blocks

            g.setColor(blk_color);
            g.fillRect(350,y_coord, 20, 20);
            //g.drawString(" " + y_coord + " ", 350, y_coord);

            g.drawRoundRect(330, 90, 350, 110, 10, 10);     //rectangular frame1
            g.drawRoundRect(330, 205, 350, 110, 10, 10);     //rectangular frame2
            g.drawRoundRect(330, 320, 350, 110, 10, 10);     //rectangular frame3

        }

        void drawCrossedblock(Graphics g, int blk_no, String name)
        {
            String str;
            Integer str2;
            y_coord= 115 +(25*(blk_no-1));
            str2=blk_no-4;
            //str=str2.toString();

            g.drawRect(350,y_coord, 20, 20);
            g.drawLine(350, y_coord, 370, y_coord+20);                      //crossing line
            g.drawLine(370, y_coord, 350,y_coord+20);                       //crossing line
            g.drawString("Stage "+ str2 +": " + name,255,y_coord + 15);           //Stage names


            
        }

        void execBlock(Graphics g,int blk_no, block B)/>
        {
        y_coord=y_coord + 10;

        try{
        Thread.currentThread().sleep(3000);//sleep for 1000 ms
        b.drawblock(g,1,Color.red);
        repaint();
        }

        catch(InterruptedException ie)
        {
        //If this thread was intrrupted by nother thread
        }

        }
        
    }

    /*public class animate_block
    {

    }*/



    public void paint(Graphics g)
    {

        block b1 = new block();
        block b2 = new block();
        block b3 = new block();
        block b4 = new block();

        block b5 = new block();
        block b6 = new block();
        block b7 = new block();
        block b8 = new block();

        b1.drawblock(g,1,Color.red);                  //drawing the blocks that represent waiting instructions
        b2.drawblock(g,2, Color.blue);
        b3.drawblock(g,3, Color.magenta);
        b4.drawblock(g,4, Color.black);

        b5.drawCrossedblock(g,5,"IF");              //drawing crossed blocks that represent executing instructions
        b6.drawCrossedblock(g,6,"ID");
        b7.drawCrossedblock(g,7,"IE");
        b8.drawCrossedblock(g,8,"WB");

//        b1.execBlock(g,1,b1);


            Font f_temp= new Font("Arial",Font.BOLD,20);
            Font f_original=new Font("Arial",Font.PLAIN,10);
                f_original=g.getFont();
                g.setFont(f_temp);
                g.drawString("Waiting Instructions", 425, 155);
                g.drawString("Pipelined Instructions", 425, 265);
                g.drawString("Completed Instructions", 425, 385);

                g.setFont(f_original);
            

           
        g.drawRect(0, 0, 1000, 604);
        g.drawImage(oscar_image, 1, 0, this);
        g.setColor(authColor);
        g.fillRect(826,0, 175, 54);     //author block
        g.setColor(titleColor);
        g.fillRect(213,0, 612, 54);     // title block
        g.fillRect(0,544, 1000, 60);    //bottom block
        

        

        /*
         try{

        g.drawString ( "theString", Xpostion, Ypostion); // Draw the string
        Thread.currentThread().sleep(125);//sleep for 1000 ms
        Xpostion=Xpostion+2; // Adjust the position one pixel to the left.
        repaint();

        }
        catch(InterruptedException ie)
        {
        //If this thread was intrrupted by nother thread
        }
         */

        

}


}



Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

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

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

Re: Java Applets

Posted 05 July 2010 - 04:13 PM

By the way your code does not even compile

		void execBlock(Graphics g,int blk_no, block B)/>
		{
			y_coord=y_coord + 10;

			try{
				Thread.sleep(3000);      <--- this is how to sleep
				B.drawblock(g,1,Color.red);    <---- you need a B here not a b


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1