Important alert: (current site time 7/15/2013 3:48:50 PM EDT)
 

VB icon

frame zig zag fun

Email
Submitted on: 7/8/2010 8:47:55 AM
By: Roniora 
Level: Beginner
User Rating: By 1 Users
Compatibility: Java (JDK 1.5)
Views: 3729
author picture
(About the author)
 
     one of first few experiments in frames and threading.... just wanted to have fun with it thats all but it should also teach beginners certain things about frames and buttons etc... little but it will its anyways not actually what i intended it to be... but have fun impress ur buddies
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: frame zig zag fun
// Description:one of first few experiments in frames and threading.... just wanted to have fun with it thats all
but it should also teach beginners certain things about frames and buttons etc... little but it will
its anyways not actually what i intended it to be... but have fun
impress ur buddies
// By: Roniora
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6676&lngWId=2//for details.//**************************************

import java.awt.*;
import java.awt.event.*;
//two frame vertical horizontal zig zag fun
 class tfvhzz extends Frame implements ActionListener, Runnable 
{
Frame f = new Frame(),ff= new Frame();
Button b= new Button("Horizontal zig zag"), bb=new Button("Vertical zig zag");
Button z= new Button("Horizontal zig zag"), zz=new Button("Vertical zig zag"); 
String s;
//not much need of buttons for second frame because only one frame's buttons require to be //pressed
Thread t=new Thread(this);
int x=10,y=10,d=10,c=20,m=10;int xx=10,yy=10;
int cx=500,cy=110,c1=5,c2=5;
tfvhzz()
{
f.setTitle("Dancing frame");
f.setSize(cx,cy);
b.addActionListener(this);
bb.addActionListener(this);
f.add(b,BorderLayout.NORTH);
f.add(bb,BorderLayout.SOUTH);
f.setVisible(true);
ff.setTitle("Dancing frame2");
ff.setSize(cx,cy);
ff.add(z,BorderLayout.NORTH);
z.addActionListener(this);
zz.addActionListener(this);
ff.add(zz,BorderLayout.SOUTH);
ff.setVisible(true);
}
void horzz() throws Exception
{c=1;
for(x=xx,y=yy;m>0;x+=d,y+=c,m+=10,cx+=c1,cy+=c2)
{
if(x>1350)
{
xx=1360;
x=xx;
d*=-1;
}
if(x<20&&d==-10)
{
xx=10;yy=500;
x=xx;
y=yy;
d*=-1;c*=-1;
}
if(y>700&&c>0)
{y=710;c*=-1;
}
if(y<10&&c<0)
{
y=10;
c*=-1;
}
if(cx>250&&c1>0)
{
cx=260;cy=260;
c1*=-1;c2*=-1;
}
else if(cx<80&&c1<0)
{
cx=cy=70;
c1*=-1;c2*=-1;
}
/*if(cy>350)
{c2*=-1;
cy=70;
}
else if(cy<80&&c2<0)
{
cy=70;
c2*=-1;
}
*/
//f.add(bb,BorderLayout.CENTER);
f.setSize(cx,cy);ff.setSize(cx,cy);
Thread.sleep(1);
f.setLocation(1366-x,768-y);ff.setLocation(x,y);
}
}
void verzz() throws Exception
{
for(x=xx,y=yy;m>0;x+=d,y+=c,m+=10,cx+=c1,cy+=c2)
{
if(x>1350)
{
xx=1360;yy=10;y=yy;
x=xx;
d*=-1;
}
if(x<20&&d==-10)
{
xx=10;yy=500;
x=xx;
y=yy;
d*=-1;c*=-1;
}
if(y>700&&c>0)
{
y=710;
c*=-1;
}
if(y<10&&c<0)
{
y=10;
c*=-1;
}
if(cx>250&&c1>0)
{
cx=260;cy=260;
c1*=-1;c2*=-1;
}
else if(cx<80&&c1<0)
{
cx=cy=70;
c1*=-1;c2*=-1;
}
/*if(cy>350)
{c2*=-1;
cy=70;
}
else if(cy<80&&c2<0)
{
cy=70;
c2*=-1;
}
*/
//f.add(b,BorderLayout.CENTER);
f.setSize(cx,cy);ff.setSize(cx,cy);
Thread.sleep(1);
f.setLocation(1366-x,768-y);ff.setLocation(x,y);
}
}
public void run()
{t.start();
}
public void actionPerformed(ActionEvent ae)
{
s=ae.getActionCommand();
try
{
if(s=="Horizontal zig zag")
{
horzz();
}
if(s=="Vertical zig zag")
{
verzz();
}
}
catch(Exception e)
{}
}
public static void main(String h[])
{
tfvhzz v = new tfvhzz();
}
}


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.