Michael Ossino

Greenhorn
+ Follow
since Dec 16, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Ossino

Thanks. I'm just tooling around with the file, and trying to increase the number of balls to 20, and adding in an even hanlder to add a new ball everytime the mouse is clicked, but it' won't go. I think I have the right idea, but it just won't compile. Here si the code I have so far:
import java.awt.*;
import java.applet.*;
class Ball
{
//the boundaries of the window and the diameter of our ball
//we tell our balls the window size by constructor, so we can
//change the applet's size easily
int width, height;
static final int diameter=30;
//coordinates and value of increment
double x, y, xinc, yinc;
Color color;
Graphics g;
//the constructor
public Ball(int w, int h, int x, int y, double xinc, double yinc, Color c)
{
width=w;
height=h;
this.x=x;
this.y=y;
this.xinc=xinc;
this.yinc=yinc;
color=c;
}
public void move()
{
x+=xinc;
y+=yinc;
//when the ball bumps against a boundary, it bounces off
if(x<0 || x>width-diameter)
{
xinc=-xinc;
x+=xinc;
}
if(y<0 || y>height-diameter)
{
yinc=-yinc;
y+=yinc;
}
}
public void paint(Graphics gr)
{
g=gr;
g.setColor(color);
//the coordinates in fillOval have to be int, so we cast
//explicitly from double to int
g.fillOval((int)x,(int)y,diameter,diameter);
}
}
public class Project32 extends Applet implements Runnable
{
Thread runner;
Image Buffer;
Graphics gBuffer;
Ball ball[];
//how many balls?
static final int MAX=20;
public void mouseClicked()
{
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
ball=new Ball[MAX];
int w=size().width;
int h=size().height;
//our balls have different start coordinates, increment values
//(speed, direction) and colors
ball[0]=new Ball(w,h,50,20,1.5,2.0,Color.blue);
ball[1]=new Ball(w,h,60,100,2.0,-3.0,Color.red);
ball[2]=new Ball(w,h,15,70,-2.0,-2.5,Color.green);
ball[3]=new Ball(w,h,150,60,-2.7,-2.0,Color.cyan);
ball[4]=new Ball(w,h,210,30,2.2,-3.5,Color.magenta);
ball[5]=new Ball(w,h,50,20,1.5,2.0,Color.blue);
ball[6]=new Ball(w,h,60,100,2.0,-3.0,Color.red);
ball[7]=new Ball(w,h,15,70,-2.0,-2.5,Color.green);
ball[8]=new Ball(w,h,150,60,-2.7,-2.0,Color.cyan);
ball[9]=new Ball(w,h,210,30,2.2,-3.5,Color.magenta);
ball[10]=new Ball(w,h,50,20,1.5,2.0,Color.blue);
ball[11]=new Ball(w,h,60,100,2.0,-3.0,Color.red);
ball[12]=new Ball(w,h,15,70,-2.0,-2.5,Color.green);
ball[13]=new Ball(w,h,150,60,-2.7,-2.0,Color.cyan);
ball[14]=new Ball(w,h,210,30,2.2,-3.5,Color.magenta);
ball[15]=new Ball(w,h,50,20,1.5,2.0,Color.blue);
ball[16]=new Ball(w,h,60,100,2.0,-3.0,Color.red);
ball[17]=new Ball(w,h,15,70,-2.0,-2.5,Color.green);
ball[18]=new Ball(w,h,150,60,-2.7,-2.0,Color.cyan);
ball[19]=new Ball(w,h,210,30,2.2,-3.5,Color.magenta);

}
public void start()
{
if (runner == null)
{
runner = new Thread (this);
runner.start();
}
}
public void stop()
{
if (runner != null)
{
runner.stop();
runner = null;
}
}
public void run()
{
while(true)
{
//Thread sleeps for 15 milliseconds here
try {runner.sleep(15);}
catch (Exception e) { }
//move our balls around
for(int i=0;i<MAX;i++)
ball[i].move();
repaint();
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
//draw a gray background and a grid of lines
gBuffer.setColor(Color.gray);
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setColor(Color.lightGray);
for(int x=0;x<size().width;x+=50)
gBuffer.drawLine(x,0,x,size().height);
for(int y=0;y<size().height;y+=50)
gBuffer.drawLine(0,y,size().width,y);
//paint our balls
for(int i=0;i<MAX;i++)
ball[i].paint(gBuffer);
g.drawImage (Buffer,0,0, this);
}
}
19 years ago
Thank you. But what about the first half of clode (ball class)? Di i put that code in the same file as project32 or as a seperate file called ball.java?
19 years ago
I came across some source code for a tutorial, I'd like to try, but for some reason I can't get the code to run. Could some please tell what I'm doing to wrong to run it, or breaking it up?thanks. here is the code:
import java.awt.*;
import java.applet.*;
class Ball
{
//the boundaries of the window and the diameter of our ball
//we tell our balls the window size by constructor, so we can
//change the applet's size easily
int width, height;
static final int diameter=30;
//coordinates and value of increment
double x, y, xinc, yinc;
Color color;
Graphics g;
//the constructor
public Ball(int w, int h, int x, int y, double xinc, double yinc, Color c)
{
width=w;
height=h;
this.x=x;
this.y=y;
this.xinc=xinc;
this.yinc=yinc;
color=c;
}
public void move()
{
x+=xinc;
y+=yinc;
//when the ball bumps against a boundary, it bounces off
if(x<0 || x>width-diameter)
{
xinc=-xinc;
x+=xinc;
}
if(y<0 || y>height-diameter)
{
yinc=-yinc;
y+=yinc;
}
}
public void paint(Graphics gr)
{
g=gr;
g.setColor(color);
//the coordinates in fillOval have to be int, so we cast
//explicitly from double to int
g.fillOval((int)x,(int)y,diameter,diameter);
}
}
public class Project32 extends Applet implements Runnable
{
Thread runner;
Image Buffer;
Graphics gBuffer;
Ball ball[];
//how many balls?
static final int MAX=5;
public void init()
{
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
ball=new Ball[MAX];
int w=size().width;
int h=size().height;
//our balls have different start coordinates, increment values
//(speed, direction) and colors
ball[0]=new Ball(w,h,50,20,1.5,2.0,Color.blue);
ball[1]=new Ball(w,h,60,100,2.0,-3.0,Color.red);
ball[2]=new Ball(w,h,15,70,-2.0,-2.5,Color.green);
ball[3]=new Ball(w,h,150,60,-2.7,-2.0,Color.cyan);
ball[4]=new Ball(w,h,210,30,2.2,-3.5,Color.magenta);
}
public void start()
{
if (runner == null)
{
runner = new Thread (this);
runner.start();
}
}
public void stop()
{
if (runner != null)
{
runner.stop();
runner = null;
}
}
public void run()
{
while(true)
{
//Thread sleeps for 15 milliseconds here
try {runner.sleep(15);}
catch (Exception e) { }
//move our balls around
for(int i=0;i<MAX;i++)
ball[i].move();
repaint();
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
//draw a gray background and a grid of lines
gBuffer.setColor(Color.gray);
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setColor(Color.lightGray);
for(int x=0;x<size().width;x+=50)
gBuffer.drawLine(x,0,x,size().height);
for(int y=0;y<size().height;y+=50)
gBuffer.drawLine(0,y,size().width,y);
//paint our balls
for(int i=0;i<MAX;i++)
ball[i].paint(gBuffer);
g.drawImage (Buffer,0,0, this);
}
}
19 years ago
Ok i got this so far, but now I'm having trouble compiling it. it won't let me compile over the Arc2D method. What am I doing wrong with it? It works fine with everything else. Also The coordinetes aren't right on the arc I plan on tweeking it after I figure out why it won't compile.
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
public class Winter extends JFrame {
public Winter()
{
super ("Winter Scene");
getContentPane().setBackground(Color.CYAN);
setSize(500,500);
setVisible(true);
}
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(Color.YELLOW);
g2d.fill (new Rectangle2D.Double(50, 200, 200, 200));
g2d.setPaint(Color.BLUE);
g2d.fill (new Rectangle2D.Double(65, 220, 50, 50));
g2d.setPaint(Color.BLUE);
g2d.fill (new Rectangle2D.Double(185, 220, 50, 50));
g2d.setPaint(Color.RED);
g2d.fill (new Rectangle2D.Double(125, 300, 50, 100));
g2d.setPaint(Color.BLUE);
g2d.fill (new Rectangle2D.Double(326, 390, 99, 40));
g2d.setPaint(Color.WHITE);
g2d.fill (new Ellipse2D.Double(325, 320, 100, 100));
g2d.setPaint(Color.WHITE);
g2d.fill (new Ellipse2D.Double(337, 260, 75, 75));
g2d.setPaint(Color.WHITE);
g2d.fill (new Ellipse2D.Double(348, 220, 50, 50));
g2d.setPaint(Color.BLACK);
g2d.fill (new Ellipse2D.Double(355, 230, 10, 10));
g2d.setPaint(Color.BLACK);
g2d.fill (new Ellipse2D.Double(378, 230, 10, 10));
g2d.setPaint(Color.BLACK);
//g2d.setStroke( new BasicStroke(1.Of));
g2d.draw (new Arc2D.Double(365,250, 40, 40, 265, 275));
}
public static void main (String args[])
{
Winter application = new Winter();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
20 years ago
I'm trying to develope an applet that will use the graphics and Java2D operators to draw a simple winter scene with a house and a snowman.
The house will be pretty simple a square house with a rectangle door, 2 square windows, a triangle for the roof, and a rectangle chimney, with 3 puffs of smoke comming out of it that are gradually bigger. Also there will be a quarter cirlce of the sun poking out of the left top of the sceen, and a cloud consisting of a few cirlces. There will also be a blue sky and white for the snowy ground.
The snowman will be 3 circles with 2 stick arms 2 buttons and a face consisting of 2 black circles for the eyes and an arc for the smile. Also the snowman will be positioned on a blue square.
Each of these will have there own methods.
So far this is all I have:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.*;
import javax.swing.*;
public class SnowmanApplet extends JApplet
{
public void paint( Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
setBackground(Color.cyan);
House house1 = new house(5,20);
Snowman snowman1 = new snowman(100,100);
house1.drawhouseouse(g2);
snowman1.drawSnowman(g2);
}
}

I doubt I have the coordinates correct though. I'm kind of rusty on my Java, could someone please give me some advice/suggestions on how to do the other parts? Thanks in advance
20 years ago
I'm trying to develope an applet that will use the graphics and Java2D operators to draw a simple winter scene with a house and a snowman. The house will be pretty simple a square house with a rectangle door, 2 square windows, a triangle for the roof, and a rectangle chimney, with 3 puffs of smoke comming out of it that are gradually bigger. Also there will be a quarter cirlce of the sun poking out of the left top of the sceen, and a cloud consisting of a few cirlces. There will also be a blue sky and white for the snowy ground.
The snowman will be 3 circles with 2 stick arms 2 buttons and a face consisting of 2 black circles for the eyes and an arc for the smile. Also the snowman will be positioned on a blue square.
Each of these will have there own methods.
So far this is all I have:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.*;
import javax.swing.*;
public class SnowmanApplet extends JApplet
{
public void paint( Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
setBackground(Color.cyan);
House house1 = new house(5,20);
Snowman snowman1 = new snowman(100,100);
house1.drawhouseouse(g2);
snowman1.drawSnowman(g2);
}
}

I doubt I have the coordinates correct though. I'm kind of rusty on my Java, could someone please give me some suggestions on how to go about the other parts? Thanks in advance
20 years ago
Yeeah sorry about that...I relized after I posted it in the beginers forum that it wasn't really a beginners topic so I posted it here. I'm new and was reffered here from another forum where I was lookling for some help on this matter. Sorry for the double post.
20 years ago
Ok i'm finishing up a beginer Java course in College and I got my last Java program/assignment that is supposed to simulate a tv remote, and a vcr remote that inherits the functions from tv remote , beign able to change the channels and volume as well. The tv remote is supposed to change the channels 1-25 relooping them, and the volume 1-10 not relooping them. The vcr is supposed to fast forward, rewind, stop, play, eject and insert the tape. The vcr has a getMode and setMode. The getMode tells the user which mode they are in and gives a message if there isn't a tape in the vcr. The setMmode is supposed to play, stop, fast forward, and rewind. It is only supposed to simulate a remote and will only display what level the volume is, which channel you are on, and which vcr feture is currently in use(play, rewind, ect). I got some help with this but it is still incomplete and I can't tell what i'm doing wrong. I still don't have a way to rewind, fast forward, stop, and play the tape or a way for the user to interface with the program. It was due today but my prof. was kind enough to give me until 9:00a.m tomorrow morning to finish this last assignment. If anyone could give me some help with this i would greatly apprecite it...i've gotten quit lost about halfway through the semester and just trying to finish this lass program. Here is the code that i have so far:
import javax.swing.JOptionPane;
public class TVRemote{
int volume = 5;
int channel = 5;
public void channelUp(){
if(channel < 25){
channel++;
}
}
public void channelDown(){
if(channel > 1){
channel--;
}
}
public void volumeUp(){
if(volume < 10){
volume++;
}
}
public void volumeDown(){
if(volume > 1){
volume--;
}
}
}
public class VCRemote extends TVRemote{
String tape = null;
String mode = "Stop";
public void insertTape(String t){
tape = t;
}
public void ejectTape(){
tape = null;
}
public void setMode(String m){
mode = m;
}
public String getMode(){
return mode;
}
}
public String getMode(){
if(tape == null){
System.out.println("There is no tape");
}
return mode;
}
Again thank you to anyone who can help me. I greatly appreciate it. Thank you.
20 years ago
Ok i'm finishing up a beginer Java course in College and I got my last Java program/assignment that is supposed to simulate a tv remote, and a vcr remote that inherits the functions from tv remote , beign able to change the channels and volume as well. The tv remote is supposed to change the channels 1-25 relooping them, and the volume 1-10 not relooping them. The vcr is supposed to fast forward, rewind, stop, play, eject and insert the tape. The vcr has a getMode and setMode. The getMode tells the user which mode they are in and gives a message if there isn't a tape in the vcr. The setMmode is supposed to play, stop, fast forward, and rewind. It is only supposed to simulate a remote and will only display what level the volume is, which channel you are on, and which vcr feture is currently in use(play, rewind, ect). I got some help with this but it is still incomplete and I can't tell what i'm doing wrong. I still don't have a way to rewind, fast forward, stop, and play the tape or a way for the user to interface with the program. It was due today but my prof. was kind enough to give me until 9:00a.m tomorrow morning to finish this last assignment. If anyone could give me some help with this i would greatly apprecite it...i've gotten quit lost about halfway through the semester and just trying to finish this lass program. Here is the code that i have so far:
import javax.swing.JOptionPane;

public class TVRemote{
int volume = 5;
int channel = 5;

public void channelUp(){
if(channel < 25){
channel++;
}
}

public void channelDown(){
if(channel > 1){
channel--;
}
}

public void volumeUp(){
if(volume < 10){
volume++;
}
}

public void volumeDown(){
if(volume > 1){
volume--;
}
}
}
public class VCRemote extends TVRemote{
String tape = null;
String mode = "Stop";

public void insertTape(String t){
tape = t;
}

public void ejectTape(){
tape = null;
}

public void setMode(String m){
mode = m;
}

public String getMode(){
return mode;
}
}

public String getMode(){
if(tape == null){
System.out.println("There is no tape");
}
return mode;
}

Again thank you to anyone who can help me. I greatly appreciate it. Thank you.
20 years ago