I have been assigned with a task to have a class which has the methods setImage and getImage. These methods are meant to set the ImageIcon by using the url taken from another class and the getImage method is meant to return the ImageIcon that was set before hand. The problem is that i'm not really familiar with ImageIcon so the code in both my methods is giving out errors and i just can't figure out why. Heres the code in the class that has the setImage and getImage methods:
public class Die implements DieInterface {
private ImageIcon [] image = new ImageIcon[6]; //the number of images that would be stored in this array is 6 (six faces of the dice)
ublic Die()
{
//This puts images into the images array(the different die faces)
image = new ImageIcon[6];
[code]....
And this is where i call the methods (set and get methods) in the other class:
i need to change my code in order to stop the member variables from being directly altered and its been suggested that i should use a setter and getter method. Ive read up about these and im still unsure at how they should be implemented into my code for my project.
A blood clinic has hired a team of software developers to build a custom application to track patients. The clinic needs to keep a record of each patient and his or her blood data. Ultimately, they want all of the information stored in a database. As a starting point, the development team leader informs the team that the application has to have a set of core classes that represent the “real-world” entities the program needs to deal with. As a developer on the team, your job is to build a Patient class along with a BloodData class so that each Patient contains a BloodData object. This principle is known as “composition.”
Building the Framework Begin by creating a public Java class named PatientBuilder that contains a main method. Then, in the same file, create a non-public class named Patient and another named BloodType. Save the file as PatientBuilder.java. Note: If this was a real development project, you would put each class into it’s own file and put the files in the same folder. By combining them all into one file, we avoid having to submit three separate files, making it easier to keep all your work in one place.The BloodData Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective:
• Create a field to hold a blood type. The four possible blood types are O, A,B, and AB. For this project, you can simply define the field as a String. • Create a field to hold the Rh factor. The two possible Rh factors are + and –.For this project, you can simply define the field as a String. • Create getter and setter methods for both fields. • Create a default constructor that sets the fields to “O” and “+” • Create an overloaded constructor that accepts two parameters – one for a proposed blood type, and another for a proposed Rh. The constructor should call the set methods and pass these parameter variables in to them.The Patient Class This class should hold all of the attributes to hold the data the clinic needs for a given patient’s blood. Implement the following capabilities to accomplish this objective: • Create a field to hold an ID number along with get and set methods. • Create a field to hold the patient’s age along with get and set methods. • Create a field to hold the BloodData for a Patient. When declaring the field, initialize it by instantiating a BloodData object. Create get and set methods. • Create a default constructor that sets the ID to “0”, age to 0, blood type of the BloodData object to “O”, and Rh value of the BloodData object to “+”. • Create an overloaded constructor that accepts the following parameters: ID,age, blood type, and Rh. The constructor should call the set methods for the field associated with each parameter.The PatientBuilder Class.This class should contain the main method from which the program runs. In that method, implement the following functionality:• Ask the user for the ID, age, blood type, and Rh factor of a Patient. • Create a Patient object, passing all of the data obtained from the user into the object. • Write the code necessary to display the ID, age, blood type, and Rh factor of the Patient by calling the appropriate get methods of the object.
MY CODE ( which does not compile since it is wrong...)
import java.util.Scanner; public class PatientBuilder { public static void main(String[] args){ String patientID; int patientAge; String patientRh; String patientBlood;
Write a class Month that represents one of the twelve months of the year. It should have three attributes for
the name of the month,
the number of days in the month, and
the birthstone.
Also add constructors and getter/setter methods to access the attributes.
You may use the following code to test your class.
Java Code:
import java.util.*; public class Month { // ADD CODE HERE!!! public static void main(String[] args) { Month[] months = new Month[12];
[Code] ....
So what I have added so far is (under public class month { :)
Java Code:
String monthName, monthBirthStone; int monthDays; public Month (String name, int days, String birthstone) { monthName = name; monthBirthStone=birthstone; monthDays=days; } mh_sh_highlight_all('java');
So I believe that is the constructor. I still do not understand several things:
What would I need the getter and setter for?
I tested it using just the above code, and using month 1 I got:
Month@5a1cfb56
This makes sense as I obviously didn't do anything in order to get it in a String format for the array. But I do not understand this still - how would I get the constructor to output a string (to then be in the array?)
I am trying to set my setter and getter various times o that I can store a name, price and value but i can only set it once. Once i try to set again the previous entry resets.I have tried
This sets the values for me and i receive the input i entered but if i try to enter again the input from before is removed.I have searched array lists and tried
[code] List<Object> list new ArrayList<Object>(); list.add(jobname) list.add(price) list.add(Event)
out.println(list.get(0));
for (Object s : list) { out.println(s); }
For this to work I would have to keep adding list.add. Is there a way I can use the array to add a new item to the list so that when I try to display what I have stored in the setter and getter it will display what I have entered in each time instead of only the last input? or any other way that may be possible to do this?
i'm trying to modify and use a GUI to set the variables the setter methods. while the code seems valid to me and should work perfectly, i get ArrayIndexOutOfBounds and StringIndexOutOfBounds and respectively lines 111 and 134. i'm am not the original author of this code, all i want is to get it to work fine.
If i have a class(lets say class name is Approval) with the following private members: String recip_id, Int accStat, String pDesc, String startDate How can i create public get and setter methods for these private members of the class?
I wrote displayAscending() and displayDescending() methods to this double linked list and it is not working at all. Logically it seems fine to me. I positioned the head in the beginning in the ascending method; created a variable named data1 as an auxiliar variable so it can store the values that are going to be moved; and moved the values. Same thing for the descending method but instead of the head I put the tail and move left the list, instead of right.
import java.util.*; class node { int data; node left; node right; node(int d, node l, node r) { data = d;
I'm at the Image part of this chapter and I wrote/copied these 2 classes:
[URL]
The error:
Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at image.Board.<init>(Board.java:17) at image.Image.<init>(Image.java:10) at image.Image.main(Image.java:20)
I'm fairly certain the problem is the path in this piece of code:
ImageIcon ii = new ImageIcon(this.getClass().getResource("C:GebruikersKristofferworkspaceImagessrcimageNature.jpeg"));
I've done some research and found that I should place the image in the same folder as my .java files, which I did [URL] but the problem still persists.
I am trying to compare a ImageIcon in a button against another. The method which has the issue is checkMatrixValues() third from the bottom of this post. I did my best to make this post flow as I am looking at the issue, hope it is not confusing.
the view class creates a matrix of Mybuttons and Mybuttons extends JButton. I did this because I need Mybuttons to have fields within each button.
public class View extends Mybuttons{ private static final long serialVersionUID = 1L; JFrame frame; JPanel matrixPanel, optionsPanel; Mybuttons[][] matrixBtn;
[Code]...
MyButtons has a few values and methods in it but here is a peek at the fields. This post is concentrating on ImageIcon greenIcon and ImageIcon redIcon.
public class Mybuttons extends JButton { private static final long serialVersionUID = 1L; Boolean barrier,startNode,targetNode,visited; public ImageIcon greenIcon = new ImageIcon("green.png"); public ImageIcon redIcon = new ImageIcon("red.png"); private ImageIcon yellowIcon = new ImageIcon("yellow.png"); private ImageIcon resetIcon = new ImageIcon("null"); public int counter;
In the controller class one method checks to make sure there is one start and one end point by calling checkMartixValues when the enter button is pressed: (FYI greenIcon is start and redIcon is end)
if(e.getSource()==view.enterBtn){ for(int i=0;i<25;i++){ for(int j=0;j<25;j++){ //Validates matrix to see if there are more then one //red or green button pressed checkMartixValues(view.matrixBtn[i][j]);
[Code]...
When I do the following:
if(matrixBtn.getIcon()==view.matrixBtn.redIcon)
It runs but jumps to the else statement. Again it is saying redIcon is not a field yet I am able to access other fields from view.matrixBtn. I even tried:
if(matrixBtn.getIcon()==buttons.redIcon) //compiles but will skip to else statement too //remember the above if statement is in the same controller class which declares public class Controller { /*The view class holds the GUI and creates a matrix of MyButtons. *Each of MyButtons will be treated as a node in the Controller Class *Consider MyButtons as the Model in the MVC design * */ View view; Mybuttons buttons;
I have question on best practice on declaring variable and using getter. Is there any performance issue if I used getter every time to access the properties values or Is better to use getter once, store in variable then use that variable whenever needed.
a) What is the best practice?
b) Also what if getter in deep level e.g. myTopObj.getInnerOne().getInnerTwo().getProp();
Option 1
Java Code: var myProp = obj.getProp(); x = myProp; y = myProp mh_sh_highlight_all('java'); Option 2 Java Code: x = obj.getProp(); y = obj.getProp(); mh_sh_highlight_all('java');
I have 2 classes. TestClassA has 1 getter and 1 setter. From my second class, TestClassB, I want to access the getter method of TestClassA. If I try to access it, I get null. How do I do it?I do not want the methods to be declared as static. How can the getter method value be printed in TestClassB (without marking anything as static)?
public class TestA { private String name; public String getName() { return name;
I am trying to do a program about a contact agenda, now, I have one JPanel that contains three sub panels (GridLayout(1,3)) where I have in the left the picture of the Contact, the middle one is not important, but the right one contains 4 JTextFields with information of the contact and one JCheckBox that indicates if the contact is a favorite or not. The thing is that I am only able to show the first contact, but I want to be able to scroll between the contacts with a Button that I have in another panel. I think I am actually scrolling among the contacts, but the panel with the information from the contact is not updating the information...
public class PanelInfoContacto extends JPanel{
// ----------------------------------------------------------------- // Constructores // ----------------------------------------------------------------- /** * Construye el panel. <br/> * @param contacto - es una referencia al contacto que muestra. contacto != null. */ public PanelInfoContacto(Contacto contacto){ setLayout(new GridLayout(1,3));
I'm working on this program for a class to create objects of a commissioned employee and union employee. Everything seems to work ok, but when I run my final pay calculation, one of my getter functions will not pass the variable for the pay into a class specific variable called check. here is the code in this function.
When I run, this function works as it returns the value when i print it to test.
however, when I do the part that says check = getWeekPay() above, it doesn't change the check variable. The only thing I have on the check variable is the dues taken out of it at the end, so it ends up being a negative number.
I have a similar problem with the other derived class's check variable. Both classes have the same variable as private but one is check the other checkC.
I have a PrimeFaces page with a calendar component on it. Radio buttons on that page work fine and call the setter method on the back end. The Calendar however doesn't call the setter. The getter method is called on page display.I'm using the PrimeFaces v 5.0 jar file.
I hope I'm putting this question in the right folder. I have an array of objects, and I have defined a setter for a variable in the object. When I call the setter, I get a NullPointerException. Here is the relevant code for the object.
public class Digit extends Thread { private int digit; public void setDigit(int digit) { this.digit = digit; } // run method follows }
Here is the portion of the main class where I define an array and then call the setter.
Digit[] digits = new Digit[10]; for (int i = 0; i < digits.length; i++) { digits[i].setDigit(i); // NullPointerException occurs here }
I'm doing a software Java GUI - JFrame form like this:
1. The user wants to click on a button that opens a bunch of images that will be displayed as thumbnail in the bottom of the JFrame . 2. Then the user wants to select/click one of the thumbnail and make appear the corresponding image in it's original size on above(center) of the JFrame.
For doing this I used 3 JPanel.
One contains a JButton that opens the jfilechoser dialog window, the second "panelPreview" is for putting the thumbnails created, and the third "panelGrande" is for the image in it's original size.
The firs part "1." is ok.
But in the second part : I got one error when I want to put the ImageIcon in to the JLabel with the further intent of displaying it.
lblBig(imgIcoVett[i]);
In this project I'm dealing with arrays of ImageIcons and JLabels, so it's a bit advanced level for me, so I'm not sure that I wrote right the part of the MouseListener too.
The error displayed by netbeans says "cannot find symbol symbol: method lbl (ImageIcon) local variables referenced from an inner class must be final or effectively final"
Here I attach the project I did with netbeans"AAAD Unlayout 2.zip", but if you just need the highlight of the code, here it is too:
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
Why in my program keys are not working, what I forgot to write?
import javax.swing.JFrame; public class Main { public static void main(String args[]) { JFrame frame = new JFrame("Stickman"); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(450, 490);