Error When Trying To Set Changing Height Value From JFrame

Jun 24, 2014

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
public class Racquet {
private static final int WIDTH = 60;
private static final int HEIGHT = 20;

[code]....

The problem arises at the portion of the code that says

private int Y = game.getHeight() - 70;

I am not actually getting any compiler errors, but when I try to run the program, the command prompt pops up with this message:

Exception in thread "main" java.lang.NullPointerException
at Racquet.<init>(Racquet.java:19)
at Game.<init>(Game.java:10)
at Game.main(game.java:58)

What I want to do is make it so a GUI object that I created moves with the screen when I change the height. If I change it to private int Y = 330; the program works just fine.

View Replies


ADVERTISEMENT

Creating Program That Will Estimate Child Height Based On Height Of Parents

Jun 19, 2014

I am trying to create a program that will estimate a child height based on the height of the parents. It should ask the user to enter a String representing the gender, so m or M for a male and f or F for a female. The program must handle both upper or lower case gender entries. I need it to ask the user for the height of both parents in two parts:

1. for Feet and store in an int variable.
2. for inches and store and int variable.

So for example if the father is 6' 2'', the user would enter 6 when asked for feet and 2 when asked for inches. Convert the height of the each parent to inches. hint 12" in one foot.

Apply the following formulas based on gender (must use an if statement(s)):

Hmale_child = ((Hmother * 13/12) + Hfather)/2
Hfemale_child = ((Hfather * 13/12) + Hmother)/2

I cannot figure out what is missing from my code

<import java.util.Scanner;
public class ChildHeight
{
public static void main(String[] args) {
Scanner scannerObject = new Scanner(System.in);
String gender;
String male;
String female;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Changing Panel In Jframe On Click Of A Button

Jun 22, 2014

I want to switch panel on click of a button and code for switching panels is written in update method (Which gets called from notify observer of another class as part of Observer pattern.

unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

playGame in Panel 1 of class 1 calls another class (class 2)and data comes in update method of class 1(Observer interface).

Now for switching panels code is in gameControllerDataProcessing . I am not able to switch the panels when this functionality runs.

However if i dont call the unoGameController.playGame(playerFirst.getText(), playerSecond.getText() and directly call the update method or directly write the switching panel code . then it works fine.

btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

[Code] .....

View Replies View Related

Error In Code While Changing String To Int Array

Mar 7, 2015

import java.io.InputStreamReader;
import java.util.Scanner;
public class FinalCombinations {
public static void main(String[] args){
//Read number of values
System.out.println("Enter the no of values");

[Code] .....

I am getting output like this

Enter the no of values
4

Enter the values
1
2
3
4

Enter the number for combination
2
C(4,2)=6
1
1
2
1
1
3
1
1
4
2
2
3
2
2
4
3
3
4

where as I want output like this..wit one array
1
2
1
3
1
4
2
3
2
4
3
4

View Replies View Related

Part Of Panel Missing - No Code Error (tried Changing Size)

Apr 20, 2014

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.*;

public class aaa extends JFrame
{
private JPanel combinationp, np, ap, dp, surgeryp, medicationp, infop; // input = name, address, days
private JLabel namelabel, addresslabel, dayslabel, infolabel;
private JTextField nametf, addresstf, daystf, selectedsurgerytf;
private JButton calcButton;

[Code] .....

View Replies View Related

JFrame Container - Unknown Class Error But Codes Looks Ok

Sep 2, 2014

I got stuck with the error "Unknown class" with the code that I copied from the book ...

import javax.swing.*;
class SwingDemo
{
// create a new JFrame container
JFrame MAIN_FRAME = new JFrame ("A Simple Swing Application");

// give the frame an initial size
MAIN_FRAME.setSize(275, 100);

// terminate the program when the user closes the application
MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[code]...

The error comes from lines 21 and 27.

21 MAIN_FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27 MAIN_FRAME.add(FIELD_LABEL);

I have tried to rewrite from scratch and still gets the same error.

View Replies View Related

Using JFrame To Open Up Log In Or Out Windows For User - Unknown Variable Error

Jul 31, 2014

I am trying to use a JFrame to open up extra windows that will prompt the user the Log In or Out, but I am getting an error with one of my variables that writes to Excel. There is something wrong with the variable "sheet" contained in the "while(i <= 4)"

private void createLabel(WritableSheet sheet) throws WriteException

WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
times = new WritableCellFormat(times10pt);
times.setWrap(true);
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);

[Code] .....

View Replies View Related

JTable Height Should Fit To The Contents

Jul 24, 2014

I have a jTable with one or 40 rows in it.

The problem is, also when I have only one row in my jTable, the size of the jTable is a little more bigger than 40 rows.

How can I say the jTable, that she should scale to the size of the content?

I don`t want that the jTable is bigger than the content. For example the picture below:

View Replies View Related

Constructor Jframe In Class Jframe Not Be Applied To Types

Jun 22, 2014

So I have this line of code...

ioexception11.addChoosableFileFilter(new Jframe());

And when I compile it gives me...

error: constructor Jframe in class Jframe cannot be applied to given types;
ioexception11.addChoosableFileFilter(new Jframe());

View Replies View Related

GUI Bars - Increment Height By About 10 Pixels

Nov 12, 2014

So I'm trying to make a bar graph, each bar will increment the height by about 10 pixels. To do this, I'm making an array of bars. For some reason, using fillrect I cannot not increase the size more than 10 by 10, if I do, it will only show the 10 by 10. I want the bars to increase in height by 10 each time.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame

[Code] .....

View Replies View Related

Java Computing Height Of Stack

Jun 2, 2015

Compute the height of a stack. Then determine whether that value is found in the stack element .

View Replies View Related

Finding Height Of Binary Search Tree?

Nov 13, 2014

So for an assignment I have to write a method that finds that height of this BST. I wrote this:

public int height(Node node)
{
if (node == null)
{
return 0;
}
else
{
return 1 +
Math.max(height(node.left),
height(node.right));
}
}

Which makes sense in my head. However, I added a couple of nodes in and realized I'm not sure how to call this method.

public static void main(String[] args) {
Tree<String, String> tree = new Tree<String, String>();
tree.add("A", "1");//some added stuff
tree.add("B", "2");
tree.add("C", "3");
tree.add("D", "4");
tree.add("E", "5");
tree.add("F", "6");
tree.add("G", "7");
tree.add("H", "8");
System.out.println(tree);
System.out.println(tree.height());

What exactly do I put in the parenthesis after tree.height? If you need to see more of my code I can do that but it is quite lengthy.

View Replies View Related

BorderLayout - How To Decrease The Height Of CENTER Position

May 5, 2014

Normally, the height of the CENTER component (or position) is greater than that of the NORTH and SOUTH components in a BorderLayout.

Is it possible to increase the size of the SOUTH component and decrease the size of the CENTER position because the jcomponents I want to add in the SOUTH component are bigger? or shall I have to change the layout and use some other layout?

View Replies View Related

Check If Height Is A Letter Between A To J - If Statement Always False

Jun 22, 2014

Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in

String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E",
"e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"};
boolean trueHeight = true; // checks if height is a letter between a-j/A-J
do {
Terminal.printLine("Input height with letters A to J");

[Code] ...

View Replies View Related

JavaFX 2.0 :: How To Dynamically Set Height Of Text Area

Jul 9, 2014

I have a requirement where in the content of the text area is dynamically populated from the database. I am able to successfully retrieve and display the data on the text area.
 
However when the content is too large, I am not able to dynamically set the height of the text area. When I try to display the same as a label, the display is flawless, dynamically sets the height as per the content. So, I tried to create a label, with same content and dynamically bind the height to the preferred height as below, but it doesn't work.
 
               // Generate User Note Description
                TextArea textArea = new TextArea();
                Label text = new Label();
             
               // SETTING THE TEXT TO A LABEL TO RETRIEVE THE HEIGHT
               text.setText(usrNotes.getNote().trim());
               
[Code] ....

View Replies View Related

JavaFX 2.0 :: How To Bind rows Height Of Two Tableview

Jan 20, 2015

I want to use to tableview one beside the other  so that they appear as a single table.  but I do not find how to bound the height rows of the two tableview.

View Replies View Related

Print Isosceles Triangle Depending On Variables Height

Nov 14, 2014

The program needs to print an isosceles triangle depending on variables Height, BorderSymbol and Interior symbol, how to do that. Here is what i did so far :

{
int height = 5;
int i = 0;
int count = 0;
String line = "";
 
[code]....

and the output is a blanc page nothing on the screen only spaces...

View Replies View Related

Draw V-shape Of Height N Entered By User With Stars

Apr 12, 2014

Am stuck in a problem that asks to write a program using nested for loops to draw a V-shape of height "n" entered by the user with stars .

View Replies View Related

Return Height Of Heap Of Sand In Bottom Of Hourglass

Nov 18, 2014

I am working on program and have been struggling to get around step 5 and 6 given below.

I have got on with the first couple of points. Where to begin with steps 5 and 6.

Java Code:

class Hourglass {
int height;
int bottomHalf;
public Hourglass (int h) {
height =h;
}
public Hourglass (){
height=3;
}

/*Write a method dropGrain that simulates one grain of sand falling into the bottom half of the Hourglass. If all the sand is already at the bottom before a grain is dropped, this method should cause the hourglass to be flipped, meaning that all the sand will be in the top again. Then, one grain of sand should fall. */

//Hint: this method can be quite short. All you need to do is update one attribute.

public void dropGrain(){
}

/*Write a method getHeapHeight() which returns the height of the heap of sand in the bottom of the hourglass.

Hint: a triangle of height h contains h*h grains (=1+3+5+...+h).

So determining the height when the amount of sand in the bottom half is a square (1,4,9,16,...) is easy. Think about what happens if the amount of sand is not exactly a square.*/

public int getHeapHeight() {
} mh_sh_highlight_all('java');

View Replies View Related

Calculating Area Of A Rectangle (height Multiply By Width)

Mar 19, 2014

I was suppose to create a simple Java program for calculating the area of a rectangle (height * width). Then check the user’s input, and make sure that they enter in a positive integer, and letting them try again if they enter in a negative number. (I'm not sure how to get them to try again.

I am suppose to use an "if" statements and indeterminate loops to achieve the solution. The program will have the following requirements:

1. Ask the user to enter in both a height and width (as an integer)
2. If the user enters in a negative number, display an error
3. If the user enters in a negative number, give them another chance to enter in the correct value
4. Calculate the area and display to the screen once two positive integers have been entered.

import java.util.Scanner;
public class RectangleAreaCalc
{
public static void main(String[] args)
{
int length;
int width;
int area;
 
[Code] ....

View Replies View Related

Java Window Settings - Open With Certain Width And Height

May 19, 2014

Any way to get my Java window to open with a certain width and height. I've been googling and haven't found to much valuable information. Here is what I have so far.

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class JavaWindow{
//Bring up the frame.
private JFrame f = new JFrame("JavaWindow");

[Code] ....

When you compile that it runs a small window. I would like that window to be bigger when the file opens.

View Replies View Related

ActionListener And GetActionCommand - Volume For Length / Width And Height?

May 17, 2013

I do not understand the getActionCommand and ActionListener concepts. This code does not resolve the volume for length, width, and height.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.awt.Container;
public class rectangularSolid extends JApplet implements ActionListener {

[Code] ....

View Replies View Related

Power Of Math - Calculate Volume Of A Cylinder By Asking User To Enter Height And Radius

Jan 29, 2015

How do you use power of math. I'm trying to write a calculator to calculate the volume of a cylinder by asking the user to enter the height and radius but when I use pow(2) it doesn't work. I imported java.lang.math class so i dont have to keep using math. for now my code runs just fine since I'm using radius * radius but I would really luv to use the power instead times each other when i have to use higher powers.

import java.util.Scanner;
import static java.lang.Math.*;
 public class Lab2 {
 public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
 
[Code] .....

View Replies View Related

Call A JFrame From Another JFrame?

Jan 23, 2015

how we call a jFrame from another jFrame .

View Replies View Related

Changing JPG DPI Value For Some Images

Sep 25, 2014

I am currently working on Java software which resize jpeg images and change DPI also. For JPEG images having app0JFIF node it works fine and the images new DPI is reflected in Photoshop. But if app0JFIF node not exist, I am trying to create a new one and set the DPI value there. Everything is going proper but if I open these images in photoshop it does not reflect new DPI but the size changes.

Java Code:

double dpi_in_inch = 0.393701 * newres;
File file1 = new File(imgName);
image = ImageIO.read(file1);
int wd, hi;
wd = (int) (newsize * dpi_in_inch);

[Code] ...

View Replies View Related

Changing Superclass Parameters?

Jul 16, 2014

My understanding was I could override a method from the superclass, including with different parameters, but when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.

The first code below is the superclass. The issue I'm having is on the second code at lines 7 and 10. The ultimate goal is to make a new class where I'm able to display various packages with or without insurance.

public class Package {
double shippingWeight;
public char shippingMethod;
final char air = 'A';
final char truck = 'T';
final char mail = 'M';
double shippingCost;

[code]....

View Replies View Related







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