Results 1 to 2 of 2
Thread: Anyone see my problem?
- 02-08-2012, 04:25 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Anyone see my problem?
/*
I can't seem to draw focus to the applet itself, it works but i need to click the running window first.
Also, i can't seem to get the results(); to run. Any feedback would be great. Project is due Monday, so i can figure it out myself but i can't seem to figure out my problem at the moment
*/
import java.awt.*;
import java.awt.font.*;
import java.util.Random;
import java.applet.*;
import java.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.KeyListener;
import java.lang.Math;
import java.applet.Applet;
/*
#############################
Physics Car applet
Side project
#############################
*/
public class physic2 extends Applet implements KeyListener
{
int x = 1;
int y = 100;
int velx = 1, vely = 0;
public final int MASS = 20;
public int momentum = MASS*velx;
public double force;
public double g;
Font bigFont;
Color redColor;
Color weirdColor;
Color bgColor = Color.blue;
Color hills = Color.green;
Color road = Color.black;
Color ylw = Color.yellow;
Color clouds = Color.white;
Color tree = new Color(139,69,19);
Color leeves = new Color(10,100,10);
private boolean b1 = true, b2 = false, b3 = false, b4 = false;
public void results() {
double resVel=0;
resVel=velx*2.5;
velx=0;
force=resVel*MASS;
g=force/9.8;
//paintR.start(); NOT WORKING
}
public void paintR (Graphics H)
{
H.setColor(road);
H.fillRect(x - 30,260,50,45);
H.setColor(redColor);
H.drawString("Force Felt: " + (force) + "n",x - 27,275);
H.drawString("G's: " + (g),x - 27,287);
for(int L=0; L>=2000; L++){System.out.print("");}
}
public void restart(){velx=1;x=1;}
public void left() {
if(velx>=1){
velx -= 1; }
}
public void right() {
velx += 1;
}
public void actionPerformed(ActionEvent e) {
b1 = !b1;
b2 = !b2;
b3 = !b3;
b4 = !b4;
}
public void stop()
{
}
public void init()
{
addKeyListener(this);
this.setSize(1200,320);
//text font
bigFont = new Font("Monotype Corsiva",Font.BOLD,10);
redColor = Color.white;
weirdColor = new Color(150,150,150);
setBackground(Color.black);
}
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
if(code == 39) {
right(); System.out.println(velx); }
if(code == 37) {
left(); System.out.println(velx); }
if(code == 32) {
restart();
}
e.consume();
}
public void paint(Graphics g)
{
setBackground(Color.black);
g.setColor(bgColor);
g.fillRect(0,0,1300,800);
g.setColor(hills);
g.fillRect(0,200,1300,800);
g.fillOval(-30,150,150,150);
g.fillOval(10,170,150,150);
g.fillOval(1100,150,150,150);
g.fillOval(1030,170,300,160);
g.setColor(road);
g.fillRect(0,210,1400,40);
g.setColor(ylw);
g.fillRect(10,225,28,10);
g.fillRect(70,225,28,10);
g.fillRect(130,225,28,10);
g.fillRect(190,225,28,10);
g.fillRect(250,225,28,10);
g.fillRect(310,225,28,10);
g.fillRect(370,225,28,10);
g.fillRect(430,225,28,10);
g.fillRect(490,225,28,10);
g.fillRect(550,225,28,10);
g.fillRect(610,225,28,10);
g.fillRect(670,225,28,10);
g.fillRect(730,225,28,10);
g.fillRect(790,225,28,10);
g.fillRect(850,225,28,10);
g.fillRect(910,225,28,10);
g.fillRect(970,225,28,10);
g.fillRect(1030,225,28,10);
g.fillRect(1090,225,28,10);
g.fillRect(1150,225,28,10);
g.fillRect(1210,225,28,10);
g.setColor(clouds);
g.fillOval(45,50,60,60);
g.fillOval(75,32,60,60);
g.fillOval(75,68,60,60);
g.fillOval(120,50,60,60);
g.fillOval(100,60,60,60);
g.fillOval(100,40,60,60);
g.fillOval(129,38,60,60);
g.fillOval(125,65,60,60);
g.fillOval(375,90,60,60);
g.fillOval(405,82,60,60);
g.fillOval(405,118,60,60);
g.fillOval(350,100,60,60);
g.fillOval(330,110,60,60);
g.fillOval(330,90,60,60);
g.fillOval(359,88,60,60);
g.fillOval(355,115,60,60);
g.fillOval(845,50,60,60);
g.fillOval(875,32,60,60);
g.fillOval(875,68,60,60);
g.fillOval(920,50,60,60);
g.fillOval(900,60,60,60);
g.fillOval(900,40,60,60);
g.fillOval(929,38,60,60);
g.fillOval(925,65,60,60);
g.fillOval(615,75,60,60);
g.fillOval(635,67,60,60);
g.fillOval(635,103,60,60);
g.fillOval(570,85,60,60);
g.fillOval(550,85,60,60);
g.fillOval(550,75,60,60);
g.fillOval(579,73,60,60);
g.fillOval(575,100,60,60);
g.fillOval(595,100,60,60);
g.setColor(tree);
g.fillRect(990,195,18,60);
g.setColor(leeves);
g.fillOval(990,180,30,30);
g.fillOval(970,160,30,30);
g.fillOval(1005,165,30,30);
g.fillOval(970,180,30,30);
g.fillOval(990,160,30,30);
g.fillOval(1000,180,30,30);
//Math
g.setColor(road);
//title
g.drawString("Physics by Dan",180,27);
g.fillRect(175,30,300,2);
g.fillRect(x + 15,260,150,45);
g.setColor(redColor);
g.drawString("Velocity: " + (velx*2.5) + "m/s",x + 17,275);
g.drawString("Mass: " + (MASS) + "kg",x + 17,287);
g.drawString("Momentum: " + (MASS*velx) + "kg*m/s",x + 17,299);
//setting color
g.setColor(weirdColor);
x+=velx;
g.setColor(weirdColor);
g.fillRect(x,220,41,20);
g.fillOval(x + 3,232,14,14);
g.fillOval(x + 23,232,14,14);
for(int QQ=0; QQ<=200000;QQ++){System.out.print("");}
if(x>=950){results();}
repaint();
g.setColor(Color.black);
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
}
- 02-08-2012, 04:27 AM #2
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks