Program That Displays A Smiley Face Bouncing Around The Screen
May 30, 2014
I am writing a program that displays a smiley face bouncing around the screen. When I load the program it just shows a blank black JFrame. Here is the panel JPanel
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ReboundPanel extends JPanel {
private final int WIDTH = 300, HEIGHT = 100;
private final int DELAY = 20, IMAGE_SIZE= 35;
private ImageIcon image;
[Code]...
I have a suspicion that it might have to do with image = new ImageIcon("happyFace.gif");
I have tried other programs using .gif and they haven't worked on my computer and I haven't been able to figure out why.
View Replies
ADVERTISEMENT
Oct 23, 2014
I'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed. The ball keeps disappearing.
//bouncing ball
float x; //ball x position
float dx = 3; //ball x direction is right, step 5
float y; //ball y position
float dy = 3;
void setup () //runs once at start
[Code] ....
View Replies
View Related
May 3, 2014
change these horizontally bouncing balls to vertically bouncing balls.
package PkgBallBounce2;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
[Code]....
View Replies
View Related
Apr 22, 2015
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:
111
251.41
222
402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {
[Code] .....
View Replies
View Related
Feb 28, 2015
I have to write a program that displays the first 100 pentagonal numbers using different methods. This is what I have so far:
Java Code:
public class FivePointOne{
public static void main(String[]args){
System.out.println("The the pentagonal numbers are: ");
}
//this method will find the penagonal numbers
public static int getPentagonalNumber(int n){
[Code] ....
But when I compile it to test it out I receive the error message "Illegal start of expression," ';' expected, and "reach end of file while parsing".
View Replies
View Related
Apr 29, 2014
I'm making a program that displays information for "employee" objects of different types. This works with a hierarchy that goes Person→ Employee→ Fulltime/Adjunct, and a driver that tests the inheritance. The Person class is given and only supplies the name, the employee class manages the year hired and the ID, and the types of employee classes manage the salaries.
One object (called staff[2]) is supposed to first be printed with default information and then later updated via set methods. I figured out how to update the name, but I don't know how to update the rest of the information because the employee's name is managed in the Person class and the reset of the information is managed in the less-general classes, and the objects are all in an array of Person.
How do I call the set methods necessary to update more of staff[2]?Output (scroll to see the updating section)
The current year is 2012
Name: Flintstone, Fred
ID Num: BR-1
Year Hired: 2005
Years Of Service: 7
Salary: 65000.12
Fulltime Type Employee
[code]....
View Replies
View Related
Nov 25, 2014
I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".
So if a user would enter 3, and output could be 0 1 1
0 1 0
1 0 1
So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...
I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.
import java.util.Scanner;
public class MatrixTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an int");
int number = input.nextInt();
MatrixClass mc = new MatrixClass(number);
[Code] .....
View Replies
View Related
Jan 22, 2015
I am writing a payroll program .The program generates random PPS numbers and then takes in users information and calculates the salary accordingly. I am using netbeans and my code is showing errors on line 18 and 42 ("cannot find symbol")on the code for grossPay(). The program seems to crash after a new PPS number is generated and will not run.
package sd_assg_2;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JOptionPane;
public class SD_ASSG_2 {
public static void main(String[] args) {
String[] newPPs = getPPSno();
[Code] ....
View Replies
View Related
Feb 23, 2015
making an app in java.i m making app that should insert smilyes in textarea while sending a message.
View Replies
View Related
Feb 6, 2014
Ok. So I have decided that taking a step back is better than trying to go forward blind. I am trying to come to an understanding of how java draws simple shapes, but continue to run into problems. I have now gone ahead and directly copied code from a book just to see if it will work. It does not. The code is just supposed to make a smiley face, but when I run it I get a bunch of errors. I have attached the code that I am trying to run and the error report at the bottom.
Java Code:
import javax.swing.JFrame;
public class DrawSmileyTest
{
public static void main( String[] args );
DrawSmiley panel = new DrawSmiley();
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add( panel );
[Code] ....
9 errors found:
File: /Users/brad/Documents/Courses/Mobile App Development/Java Intermediate/Assignments/Assignment 1/DrawSmileyTest.java [line: 10]
Error: /Users/brad/Documents/Courses/Mobile App Development/Java Intermediate/Assignments/Assignment 1/DrawSmileyTest.java:10: <identifier> expected
[Code] .....
View Replies
View Related
Dec 3, 2014
My homework is asking me to write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password"
Sample
enter a string for password: wewewx
valid password
It's being graded on
Design of my GUI
Dialog box
User friendliness
Creativity
My current issues with the current code I have written is simply the password doesn't work unless it starts with 2 digits, the other order it displays as wrong. and I have no idea how to add a GUI.
import java.util.*;
import java.lang.String;
import java.lang.Character;
[code]....
View Replies
View Related
May 3, 2014
I'm new to java and I need changing the direction of these balls from a horizontal axis to a vertical axis bouncing in the center. I've tried reversing the integers but there seems to be something i've missed.
package package_bouncingball;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class Class_bouncingball extends Applet implements Runnable
{
int x_pos1 = 150;
[Code]...
View Replies
View Related
Sep 3, 2014
I want to do face detection on the camera.
View Replies
View Related
Jul 5, 2014
-The assignment asked us to make a program that looks like this.Want it to look like.jpg
-My application currently looks like this.Currently Looks Like.jpg
The update button and check boxes all work, I'm just having issues getting it to look like its suppose to. I also can't figure out how to draw a JLabel on top of another JLabel, essentially stacking them on top of each other, that's why the back of the head isn't being drawn. This is the source code of my program, I use Eclipse in case your wondering.faceAppSource.rar
So what I need is the repositioning of the left menu bar so it looks similar to the example picture, and I need to create a filled circle for the shape of the head in the right panel either with a ImageIcon or a fillOval().
View Replies
View Related
Jan 2, 2015
what im trying to do is modify the Coin class to override the toString() method so that it indicates whether the coin is face up or face down. For example, "The coin is face up." This is what i have so far:
public class Coin {
public static void main(String[] args) {
Coin coin = new Coin();
for (int i = 0; i < 1; i++) {
coin.flip();
System.out.println(coin);
[Code] .....
View Replies
View Related
Mar 16, 2015
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
Here is the code from my CardLayout:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
[Code] ....
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
[Code] ....
Once again kept to a minimal.
View Replies
View Related
May 9, 2015
I have to implement a face that smiles and frowns. I figured the easiest way to do this was to use JButtons. I also can't close the applet without hitting "end program". I was given a bit of code and had to add onto it. Here's what I have so far.
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.*;
public class AnimationFace extends JFrame {
public static final int WINDOW_WIDTH = 400;
public static final int WINDOW_HEIGHT = 400;
[Code] .....
It's 90% done but once I changed the face from smile to frown, it lost an eyeball.
View Replies
View Related
Jun 20, 2014
why this code only displays four zeros ?????
public class VargjetUshtrimi2 {
public static void main (String a []) {
int r[] = new int[11];
for (int i = 1 ;i < 10; i++)
{System.out.println( r[i] );}
}
View Replies
View Related
Dec 31, 2014
I am trying to write a java application that displays composite numbers between 1 and 100. Here is the format of my code:
//a java application that prints out composite numbers that range from 1 to 100
public class printcomposites{
public static void main(String[] args){
int num=0;
int i=0;
String printcomposites="";
for(i=1; i<100; i++)
[code]...
My code compiles with no errors, but my code generates every integer between 1 and 100 instead of integers that are composite:
Composite numbers from 1 to 100 are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 5
7 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
What am I doing incorrectly?
View Replies
View Related
Mar 3, 2015
one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.
View Replies
View Related
May 9, 2014
I'm having trouble with this program. In my textbook it says "Write an application that displays a frame containing two panels. Each panel should contain two images (use four unique images - your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does". I successfully imported the images, but I can't find out anywhere how to allow the second panel to change size with the window.
import java.awt.*;
import javax.swing.*;
public class TwoPanels
{
public static void main(String[] args)
{
JFrame frame = new JFrame ("Embedded Images");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon iconOne = new ImageIcon ("glove.jpg");
ImageIcon iconTwo = new ImageIcon ("cleats.jpg");
ImageIcon iconThr = new ImageIcon ("bat.jpg");
ImageIcon iconFou = new ImageIcon ("baseball.jpg");
[code]...
View Replies
View Related
Oct 16, 2014
As much as a clock and a calender have to do with date and time, a question arose.
I am creating a clock that displays different TIME in different captials.
Date timestamp = new Date();
timestamp.setTime(timestamp.getTime());
DateFormat time = new SimpleDateFormat("HH:mm:ss");
time.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(time.format(timestamp));
This code, returns the current time in UTC 00:00, the center of the time measuring system. And my program either ADDS an hour to the timestamp or deletes an hour, to make it earlier. My question is: Does Java account for Daylight Savings Time?
On that day, hours shift, and does java shift with them? Is there a changed need to make my code in order to not get the wrong results after the daylight savings time has hit?
View Replies
View Related
Jun 1, 2014
The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.
import java.util.*;
public class C5_17 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of lines: ");
[Code] ....
View Replies
View Related
Oct 16, 2014
Having just started college, Bob has been busy looking for a part-time job to fund his new college social life and after only two weeks of looking he has managed to get two job offers! Each job comes with different hours, basic rates of pay and over-time rates so he needs to work out which would get him the most money.
Develop an application that would allow Bob to enter his basic pay rate, his number of regular hours work per week and his number of overtime hours per week. The application should then calculate and display Bobs total basic pay for the week, his overtime pay for the week and his total pay including overtime.
Your application should use instantiable classes to separate the calculations from the user input and output.
Save the instantiable class as Pay.java
Note: The overtime rate is 1.5 times the basic rate of pay
This is my instantiable class code which compiles correctly
public class Pay{
//Declare Data members/Variables
private double pay;
private double hours;
private double overtime;
private double totalBasicPay;
[Code] .....
My errors in the second bit of code that i have never seen before
"C:UsersAndreDownloadsPayApp.java:25: error: no suitable method found for println(<null>,String)
System.out.println(null,"Please enter Basic Pay");
^
method PrintStream.println() is not applicable
(actual and formal argument lists differ in length)
[Code] .....
View Replies
View Related
Nov 27, 2014
I have a bookings table where customers can view their bookings and in the table there is a button with a command button that onclick goes to the dialogue to display the variable petUpdate value but if you have 2 bookings then all the update buttons display the value of the last petUpdate in the arrayList.
DataTable with the button
<p:dataTable
id="bookingTable"
var="customerBooking"
value="#{booking.sessionBookingList}"
editable="true"
style="margin:0px 0px 20px 100px;font-size:15px;width:600px;"
>
Code in the above datatable.......The commented out output label displays the correct value for each but when the button is clicked the dialog only displays the last ones value
<p:column headerText="Check Updates" style ="width:50px;">
<!-- <h:outputLabel value="#{customerBooking.petUpdate}"></h:outputLabel> -->
<p:dialog header="#{customerBooking.petName}'s Status" widgetVar="dlg1" minHeight="60" minWidth="60" maxWidth="60">
<h:outputText value="#{customerBooking.getPetUpdate()}" />
</p:dialog>
<p:commandButton value="?" onclick="PF('dlg1').show();" style ="width:40px;">
</p:commandButton>
</p:column>
View Replies
View Related
Aug 9, 2014
I'm working on a problem where I have to use the FileInputStream to opens a file that contains the name of a user's favorite book and then displays it.
If the file doesn't exist, then I prompt for the book title and write it to the file using FileOutputStream. This is what I have so far but I'm lost because if I put a file that exists in line 8 then it closes, but if I don't and the user puts their favorite book nothing happens. Or, as far as I can tell nothing does.
import java.io.*;
class DisplayBook {
public static void main(String[] args)
[code]....
View Replies
View Related