Simple Three Button Program

Dec 14, 2014

I have my program set up I thought correctly. When I click the buttons, nothing is happening.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RobertMaloneChapter18 extends JFrame
{
//set final sizes for window
private static final int WIDTH = 300;
private static final int HEIGHT = 200;

[code]....

View Replies


ADVERTISEMENT

Create A Simple GUI With One Button That Just Says Play

Feb 25, 2014

I am new to Java, I am using Netbeans to create a simple GUI with one button that just says "play". I want this to play an mp3 file i specify. I have found code to simply play a WAV which works great.There is lots of information on the net about playing an mp3 but it's all long an complicated. There must be a simple way to just have java play an mp3 file.

View Replies View Related

Simple Frame Button And Text Label

Jun 2, 2014

why this code doesnt work? Its suppose to be a simple frame with a button that puts text to the frame when u click it. The problem is actionPerformed method, when it tries to call the stuff inside the constructor it all goes wrong. I switched the method body with a system.out.println() and it all works fine.

import java.java.awt.Label;
import java.awt.Button
import java.awt.BorderLayout;
import java.event.*;
public class TheClass implements ActionListener {
public TheConstructor() {

[code]....

View Replies View Related

Running A Simple GUI Program

Nov 23, 2014

I'm getting back into the swing of things with Java after using I'm asked to utilize a simple GUI in order to take in the starting data, I cannot seem to get this to work. I'm getting this error Exception in thread "main" java.lang.NullPointerException

at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Input.buildPanel(Input.java:53)
at Input.<init>(Input.java:27)
at InputDemo.main(InputDemo.java:5)

I've created two classes

import javax.swing.*;
public class Input extends JFrame {
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel1;
private JLabel messageLabel2;
private JTextField shiftHrs;

[code]....

View Replies View Related

Simple Pyramid Program

Jun 28, 2014

I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result.

package asgn2;
import acm.graphics.*;
import acm.program.*;
public class pyramid extends GraphicsProgram {
private static final int BRICK_WIDTH = 30;
private static final int BRICK_HEIGHT = 12;
private static final int BASE_BRICKS =14;

[code]...

View Replies View Related

Simple Averaging Program Using Two Different Classes?

Apr 9, 2014

This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:

- 1st Class

import java.util.Scanner;
public class Main {
public static int num;
public static int total = 0;
public static int average;

[Code].....

Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.

View Replies View Related

Exception Errors In Simple Program?

Mar 26, 2015

I'm trying to read lines from a textfile and count all the words using String Tokenizer. However I keep getting an error "Unhandled exception type FileNotFoundException" on my IDE(Eclipse) referring to lines 13 and 8. When I let the IDE automatically, and I've even tried typing this manually, insert a try-catch block more errors show up concerning inputFile. When I insert the throws FileNotFoundException for each method it compiles but after running it gives me a FileNotFoundException for textfile.txt. What's even more interesting is that when I copy the .java file out of the IDE project folder, place it in a random empty folder on the Desktop with the textfile.txt, and try running it through command line, it gives a NoSuchElementException: No line found.

import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;

[Code].....

View Replies View Related

Simple Encryption / Decryption Program

Nov 1, 2014

I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far. I'm kind of lost on what to do next in the code.

import java.util.Scanner;

/*Program that encrypts then decrypts a sentence
Encryption
*/
public class Encryption extends java.swing.JFrame{

[code]....

View Replies View Related

Make A Simple Calculator Program

Mar 11, 2015

i am working on my assignment in Compro 2, we are ask to make a simple calculator program

here's my code;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

[code]...

View Replies View Related

How To Make A Simple Connect Four Program Without GUI

Nov 19, 2014

My code below is trying to make a connect four program without GUI. I'm having trouble with getting the players to make their moves. What should I put in my "makeAMove" method...

Java Code:

public class Connect

final static int MAXROW = 6;
final static int MAXCOL = 7;
public static void main(String[] args){

[code]....

View Replies View Related

Simple Vending Machine Program

Jan 22, 2014

I am having a difficult time writing what started out as a simple vending machine program. As I go on though, it seems that I'm overcomplicating it and it is getting messy, so I have resorted to the forum before I really get off the path. how to clean it up? I'm going to list a few of the problems I am having with the code below:

1. The user is supposed to enter his/her money and the program is to read each value separately (Do-While loop) and keep a running total of the money entered. I can't seem to get the right code format to do this. I was trying to do this with the variable total and so that is why the total exists in the switch statement, but it did not work.

2. In the second Do-While statement, is there a way to kick back an error when their are insufficient funds to purchase an item? Instead of getting a negative change return.

package practice;
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
double count, total;
int item;
//Display Available Options To Customer
Scanner input = new Scanner(System.in);
System.out.println("*VENDING MACHINE*");

[code]....

View Replies View Related

Simple 2D Optics Simulation Program

Sep 13, 2014

I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.

Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.

Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg

I wrote 7 classes:

Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.

What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:

Intersection sec = new Intersection(ray,(Mirror)obj);

creates an intersection with a null point.

I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).

I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.

I've found out that my function:

public PVector getNormal(PVector D){
D.normalize();
return new PVector(D.y,-D.x);
}

Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!

The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:

Optics: (note line 64. this line returns a null intersection when it shouldn't)

package ofer.davidson;
 import java.util.ArrayList;
 public class Optics {
 //Arrays to store all the optics objects and rays that are created
ArrayList<Object> objects;
ArrayList<Ray> rays;
 
[Code] .....

Also why doesn't my background turn white??

View Replies View Related

Make Simple Program Which Takes In Argument?

May 12, 2015

So I'm trying to make a simple program which takes in an argument (target) and then looks through an ArrayList of strings. If it finds a string that begins with (target) then it will return the index of that string. If it doesn't find a string which begins with (target) then it will return -1 instead.

For some reason, the program is always returning -1, rather than the index of the string within the ArrayList when there is one which matches the search criteria.

Here is the code:

public int getIndex(ArrayList<String> text, String target)
{
int i = 0;
int index = -1;
boolean found = false;

[Code].....

View Replies View Related

Program To Simulate Operation Of Simple Robot

Apr 26, 2015

Write a program to simulate the operation of a simple robot. The robot moves in four directions: Forward, backwawrd, left, and right. The job of the robot is to move items and place it in the right slots in each station. There are 8 stations plus the pickup station. Pick up station is the initial start where the robot picks the items. 8 items can be placed on each station. The nearest station must be filled before placing items on the next station. The items are marked with identification or serial numbers. The items with odd serial number go to the right and items with even number go to the eft. The last slot, number 7 is reserved for light items which are less than 80kg. The serial number is a five digit number, the MSB digit 5 indicates that the product must be placed in the fifth station which is keeping the product at 20 degree F.

View Replies View Related

Creating A Program That Calculates Simple And Compound Interest

Aug 12, 2014

I need getting started designing and creating a program that calculates simple and compound interest. Simple interest in this case means that interest is only applied to the original amount. For instance, if a person deposits $1000 at 10% annual interest, then after one year they would have $1100 (the original $1000 plus the $100 interest) and after two years they would have $1200 (the original $1000, plus the $100 earned the first year, plus the $100 earned the second year).

With compound interest, the interest is applied to all money earned. So, starting with $1000 at 10% annual interest, after one year the user would have $1100 (the original amount plus $100 interest) and after two years the user would have $1210 (the $1100 they started with at the beginning of the year plus the $110 interest).

The requirements of this program are:

-Create a class that will hold methods to calculate the interest. Do not include the main method in this class.
-In the class that is used to calculate the interest, include a method to print to the screen, by interest period, the starting amount for the period, the interest earned for the period, and the total amount at the end of the period. Note that each period represents the time frame for how often it is updated. If annual is selected the period is every year. If it is semi-annual it is every six months. If it is quarterly it is every three months.
-Create a demo class that will use your interest calculation class. Prompt the user for the original amount, the type of interest (simple or compound), the annual interest rate, and whether it is updated annually, semi-annually, or quarterly. Use method calls to your calculate interest class to do all calculations and display the result. Loop the program until the user chooses to quit.

Sample output ($10000 initial investment, 10% simple interest, annual, for 4 years):

Period Beginning Amount Interest Earned Ending Amount
1 10000.00 1000.00 11000.00
2 11000.00 1000.00 12000.00
3 12000.00 1000.00 13000.00
4 13000.00 1000.00 14000.00

View Replies View Related

Simple Chat Program With Client / Server EOFException

Feb 13, 2015

When I Start Server and login from client everything goes fine but as soon as I want to send amessage or use showIn or even logOut .

Get below error

Exception creating new Input/output Streams: java.io.EOFException

View Replies View Related

Getting NullPointer Exception Error In Simple ArrayList Program

Mar 21, 2015

I am creating a simple ArrayList program that would enable one to input their username to it using a scanner. However, i am getting this error: "Exception in thread "main" java.lang.NullPointerException

at home.Members.addUser(Members.java:16)
at home.Main.main(Main.java:14)"

Here is the code! :

Main.java class
Java Code: import java.util.Scanner;
public class Main {

[code]....

View Replies View Related

Simple Logic Error In Cipher-shifting Program?

Feb 8, 2015

I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.

This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY

Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:

public class SimpleEncryption {

/**
* @param args the command line arguments
*/
static int answer;
public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses"
+ " a basic cipher shift.");

[code]....

View Replies View Related

Simple Program In Java (Eclipse) That Converts Fahrenheit To Celsius

Apr 10, 2014

I've made a simple program in Java (Eclipse) that converts Fahrenheit to Celsius.The class is:

Java Code: package ehu.student;
public class ConversorTemperaturas {
/*--------------------------------------------------------------*/
/*Clase que dado una temperatura en Fahrenheit la canvierte en C*/
/*--------------------------------------------------------------*/
public float farenheit2celsius (float d){
float celsius, aux;

[code]...

When I write t.farenheit2celsius(25.6), appears the following error: "The method farenheit2celsisus(float) in the type ConversorTemperaturas is not applicable for the arguments (double)"If i change in the class the type float for double there is not problem. Why can't i use the type float?

View Replies View Related

Simple Program Giving Negative Result For Amount Of Calculations Done

Mar 5, 2014

Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).

Java Code:

class Benchmark {
public static void main(String[] args) {
long endTime = System.currentTimeMillis() + 60000;
int count = 0;
for (int i = 0; System.currentTimeMillis() < endTime; i++) {
double x = Math.sqrt(System.currentTimeMillis());
count = i;
}
System.out.print(count + " calculations per minute");
}
} mh_sh_highlight_all('java');

I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?

View Replies View Related

JDBC :: Simple Java Program Execution Time Varies All Over The Place

Mar 5, 2012

I've got a very simple java program (J.java, see below) on my application server that successfully connects to an Oracle 11.2 database on a database server (both servers are Linux CentOS) using JDBC thin driver from Oracle.

As you can see from the setURL command in the Java code below, I've configured the application and database servers to sit next to each other, and they're on the same network (cross-cable connected to each other), so there's no network traffic on these (development) boxes except my code.

The problem is the execution time varies a lot. If I run it 5 times, it (seemingly randomly) could take 0.01 seconds, or 10 seconds, or 50 seconds, or over a minute to execute. If it takes over a minute (roughly), the program doesn't complete, but the error shown below is returned instead.

------error returned when execution take more than about 1 minute-------
gf@host9 [~/dbwork]# java -cp ./ojdbc6_g.jar:. J
Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Connection reset
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:494)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:547)

[Code] ....

----------the java code for: J.java-------
// To compile: # javac -cp ./ojdbc6_g.jar:. J.java
// To run: # java -cp ./ojdbc6_g.jar:. J

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class J {
public static void main(String args[]) throws SQLException {

[Code] ....

View Replies View Related

Program Exits Even When Click No Or X Button On Upper Corner

Mar 31, 2015

Here is the snippet of code that is causing the problem

Java Code:

addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int confirm = JOptionPane.showOptionDialog(
VendorMachineSimulation.this,
"Are You Sure you want to close this application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,

[Code] ....

My question is why does the snippet code at the top works in the class processAction but when I add to the main class that extends JFrame, it exits regardless if I click yes, no or the x button.

View Replies View Related

Grade Average Program - Hit Button Reseved For Calculations

Nov 23, 2014

I have written a simple grade average program. This is my code:

package programs;
 import java.util.Scanner;
 public class GradeAverage {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
int number;
int counter = 0;
int grade;
 
[Code] ....

Now the program is working just fine but what I don't like about it is the fact that you have to enter the number of grades before entering the grades. What I would prefer is to write your grades, hit some button that is reserved for calculating the average and then get the output.

View Replies View Related

When Click On New Button / All Icons Except Button Just Clicked Don't Display

Oct 16, 2014

The gist of it is to create a very basic memory game. There are 12 buttons, each associated with an icon. Every button that you click will display the icon and will stay there until clicked again. I got the bulk of it taken care of, but my issue lies with switching the icons back and forth. I can get them to display one at a time, but when I click on a new button, all the icons except the button I just clicked don't display. Essentially, only one shows up at a time.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;

[code]....

View Replies View Related

JSF :: How To Make Focus To Button During Onload If Button Is In TabbedPane

Feb 24, 2015

I am using JS, how we can make focus to a button during onload, the button need to get focus which is in tabbedPane tab Name : (Search Critera1) using javascript.

View Replies View Related

How To Get Which Button Clicked In Through GetActionCommand When Button Have No Label

Sep 16, 2014

I have a JButton with a .PNG icon on it. I want to get that button click in actionPerformed Method but Jbutton have no Label... How i will know that which button clicked?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved