Java Getters - How To Reuse Them
Jul 16, 2014
I am working on this project and I wanted to know if it was possible to re-use a getter, instead of having to create one for each return value (they are all of the type JPanel).
public class GamePanels {
JPanel begin, middle, end;
public void begin(){
begin = new JPanel();
begin.setBackground(Color.MAGENTA);
[Code] ....
And this is a snippet from the class which is using this class:
newButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
GamePanels g = new GamePanels();
g.begin();
container.add("Begin", g.getPanel());
cl.show(container, "Begin");
}
});
My question is, instead of creating a huge number of getters and then remembering which getter I need, is there a way to re-use the same one? Like maybe I can add a parameter?
View Replies
ADVERTISEMENT
Oct 29, 2014
You should write a class that represents a circle object and includes the following:
1. Private class variables that store the radius and centre coordinates of the object.
2. Constructors to create circle objects with nothing supplied, with just a radius value supplied and with a radius and centre coordinates supplied.
3. Public instance methods that allow the radius and centre coordinates to be set and retrieved (often known as set/get methods).
4. Public instance methods that return the circumference and area of the circle.
5. A public class method that tests if two circle objects overlap or not
Here is my code:
import java.lang.Math;
public class Circle {
private double xCentre, yCentre, Radius;
// constructors
public Circle() {
xCentre = 0.0;
yCentre = 0.0;
Radius = 1.0;
[Code] ....
The second program just has to demonstrate each aspect addressed in the brief I pasted at the top.s of what else I can do.
This is as far as I got during the 3 hour lab session I had and both compiled fine but when running just displayed all the text eg. "Circumference of first circle is ", but didn't display any numeric values. I don't have the facilities to actually run the program unless I'm in the computer lab, I have a short opportunity to go in tomorrow but that will be the last so I'm doubtful that I'll get it fully working in time.
The problem is that when this code runs it doesn't display any numerical values, ie nothing is being passed between the two programs.
View Replies
View Related
Nov 8, 2014
I am trying to create a form where my customer can add some other fields(like: label,textbox), and he need to use that added fields for the next time he open the application...
I would like to know whether it is possible to save dynamically created controls and reuse it again...
View Replies
View Related
May 30, 2015
Should we always use getters/setters, e.g. even in something like
Java Code:
class Foo {
private static int foo;
public int getFoo() {
return foo;
}
public void setFoo(int fig) {
foo = fig;
}
} mh_sh_highlight_all('java');
Or should we use the only when there is a good reason to use them, e.g. validation for a setter or may be computing a value to return from some variables etc. ?
View Replies
View Related
Apr 14, 2014
I am new a creating GUIs and am not quite sure how to correctly make one. I have done the inheritance parts, and created two extra appliances: a washer and dryer. Now Creating the GUI ....
Here are the instructions to my project.
Introduction to GUIs (+ some inheritance)
For this assignment, you are going to create a user interface that interacts with the setters and getters of some classes that you will create.
First, create an abstract class called Appliance. This abstract class should have two attributes (dealing with household appliances) and two abstract methods called turnOn() and turnOff(). These methods should return void.
Then, create two subclasses of Appliance that represent household appliances (like a Refrigerator or Stove ((don't use those!))). These subclasses should have two attributes that are specific to the various appliance. Each subclass should implement the turnOn() and turnOff() methods. These methods should print to the command line some information about the appliance as it turns on and off.
Now, the fun part! Create a GUI interface!
Your window should have two panels: one for each appliance subclass. Each panel should have 4 textboxes (with appropriate labels) to receive/display information that correspond to the 4 attributes (2 from Appliance and 2 from the subclass) for each subclass.You also need 2 buttons on each panel: A Get button and a Set button.
When the Get button is pressed, the text boxes should be filled with the information from the instantiated object of the appropriate subclass. When the Set button is pressed, the object should then contain the information contained that the user has altered.
In your main method, you should create an object of each subclass, and prefill it with information (either using the constructor or the setters), then display your GUI. You should now be able to get and set the information for your objects from the GUI.
At least one of your attributes for each subclass should be numeric
Note that you will need to handle incorrectly formatted input (You can use exception handling to do this if you want to. Wrapper classes also will work)
If there is text in the boxes when the "Get" button is pressed, it should be overwritten by what is in the object. Remember that these two panels should both be on screen at the same time.
You don't need 2 different windows, one window: 2 panels.
View Replies
View Related
Sep 12, 2014
I have tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.
View Replies
View Related
Oct 24, 2014
I want to develop a Java program that uses OpenScript APIs to test my applications. The OpenScript framework automatically creates the Java Code so I was thinking of either using this code or create my own using the APIs.
I tried both options using NetBeans but I'm getting errors everywhere starting with the library import. I'm pretty new to Java so I'm sure I'm missing a lot of things here. I pasted the code below from the OpenScript framework that want to use in a stand-alone file for your reference.,
import oracle.oats.scripting.modules.basic.api.*;
import oracle.oats.scripting.modules.browser.api.*;
import oracle.oats.scripting.modules.functionalTest.api.*;
import oracle.oats.scripting.modules.utilities.api.*;
import oracle.oats.scripting.modules.utilities.api.sql.*;
[Code] ....
View Replies
View Related
Apr 9, 2015
I've written a java application with several classes all in the same .java file. It works just fine. Now, I've broken it up so that each class has its own .java file. Still works fine. My next step is to put those classes into a package, but I'm not about to get the program to run.The .java source files are all in /home/user/src
I've set the CLASSPATH to /home/user/src..All of the source files have "package com.myfirm.program" on the first line.I compiled the application with:
javac -d . File1.java File2.java File3.java (etc...)
the compiler created the directory: /home/user/src/com/myfirm/program and put all of the .class files in there.So how do I get the program to run? if I run from /home/usr/src
java File1
I get: Exception in thread "main" java.lang.NoClassDefFoundError: File1 (wrong name: com/myfirm/program/Program)
View Replies
View Related
Apr 14, 2015
I create 2 files:
CircleCalculationMethod.javaMain.java
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...
I use Eclipse software
View Replies
View Related
Sep 19, 2014
The title of Question might seem old and previously asked.But I have a Question that what is difference between javaSE and Java EE.Although I knew what comes under JavaSE and What is under JavaEE.But My question is that.
What happens when we add PATH in our Environment Variable How does Eclipse or Other IDE use it?
Second Question is.
For Java SE we declare a Path Variable but for Java EE we do not add any library?(I know we add some jar file like for Servlet(Servlet-api.jar) and for EJB(Ejb.jar),But What is actaul difference?
View Replies
View Related
Oct 23, 2014
creating a program that will output something like this:
Enter an Integer: 1405302(user inputted)
Your integer contains 2 even digit(s), 3 odd digit(s), and 2 zero(s).
View Replies
View Related
Dec 4, 2014
I know about coding in general, Java, C, Python, SQL etc. but I barely know anything about making code come together on the web. I have a vague idea about what things like libraries and frameworks are,I'm interested in making a web application with which relies on Java do to the data processing. The idea is that the user inputs some messages, clicks submit, the text is taken away and processed, and the results are displayed on the screen. I would like the UI to be smooth with a modern look and feel.
Also, I usually do programming on Windows but I could also use Linux, so if I'll come across any specific drawbacks using Windows.
View Replies
View Related
Jan 9, 2015
How do I specify the Working directory where the Java app is located? It may be different on different machines.
View Replies
View Related
Apr 8, 2015
what is seriazable.But I am not able to come that why it is used and when should I declare my class(Object) as serialzable and when not?
View Replies
View Related
Aug 9, 2014
i need to develop a API in java. that API will be communicate with the some site. Need to import and export the contacts into that site databases.
View Replies
View Related
Oct 30, 2014
When I try to convert this value, "Testingu2120" (along with UTF coed u2120)comes as a string as part of SOAP response. I need to convert this UTF-8 characters in to a symbol, in this case it is SM (Service Mark) symbol and show it on the UI.
How can we achieve this in JAVA?
I have four different UTF-8 character set to convert.
TM - u2122
SM -u2120
R - u00AE
C - u00A9
View Replies
View Related
Sep 17, 2014
I would like my application to execute a command in cmd. The command looks like
start "" /D "C:Riot GamesLeague of LegendsRADSsolutionslol_game_client_sln
elease s .0.1.55deploy"
"League of Legends.exe" "8394" "LoLLauncher.exe" ""
"spectator 95.172.65.26:8088 P3hNrXYZlaM3iJ9ximtzJWHbwLhvbimJ 953089676 EUN1"
So my question is how do I do this?
I tried this, (just copy paste the command):
package MyProject;
import java.io.IOException;
import java.io.InputStream;
public class Cmd {
public static void main(String[] args) {
try {
final Process process = Runtime.getRuntime().exec("start "" /D "C:Riot GamesLeague of
[code]....
View Replies
View Related
Mar 22, 2015
We started learning about tables and have a little program. The teacher gave us an excercise and doesn't works (not running), I receive too many errors. So any simple java program with tables with 20 numbers, that is giving random numbers?
View Replies
View Related
Feb 4, 2014
Write a function (or functions) that given a collection of files will produce a sum of integers from each line of each file. Each file can have any number of lines from 1 to N. Each line can contain only one integer and no other alphanumeric characters. All of the numbers from all of the files should be added to the final result. The result is just one number.
For either, what we are looking for is:
1. Clear separation of concerns
2. Well defined objects / interfaces
3. Application of good OO design principles to solve the problem
4. No code duplication
5. Test Driven Development
6. Well refactored code
7. Well tested code
View Replies
View Related
Nov 13, 2014
I have to create a new project in which i have to take the inputs from the user and create the XML schema out of this. How can I do this the best way .
View Replies
View Related
Aug 12, 2014
I am trying to run a Powershell command from Java that creates an Active Directory group. I don't get any errors, but it doesn't work either. I can take the output from this class and plug it into the CMD prompt and it works fine.
Java Code:
public class CreateAD {
public int creategroup(String groupname, String description){
String runadcreate;
int errorfree =0;
runadcreate = "powershell Import-Module ActiveDirectory
[code]...
View Replies
View Related
Dec 22, 2014
I'm converting from ASP to Java for a legacy site. I believe the first part of the if statement is right but I'm having an issue within the else staetment. I'm getting date is undefined, I've tried using getYear and getDate but have not been successful.
ASP:
If Request("action") = "results" Then
aMonth = Request("selMonth")
aDate = cint(Request("selDate"))
aYear = cint(Request("selYear"))
Else
aMonth = UCase(MonthName(Month(Date()),true))
aDate = Day(DateAdd("d",-1,date()))
aYear = Year(Date())
End If
[code]....
View Replies
View Related
Apr 16, 2014
how to use JFrames and button and so on in Java. I found this video on youtube and followed it along, however even though my program is virtually identical to his, I'm still getting errors.
Here's the video I was watching: Video
And here's my code:
import javax.swing.*; //Imports JFrame and JButton for use
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.*;
import java.awt.*;
import java.awt.event.*;
public class swing
[code]....
The reason why I'm importing some many things is I'm trying everything to try fix my problem.
He's the error messages I'm getting:
frame2.add(panel);
^
C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression
frame2.add(panel);
[code]....
I used to make the button just create another frame without additional labels but I changed it to be even more similar to his program just to rule everything out. Also initially my program varied quite a bit, I've changed everything to be like his. Even without the ";" error I got, I kept telling me I was not allowed have my class as static, even though the guy in the video has it set to static. Also I don't think my "setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);" is working as it doesn't change color.
I think the problem is with my panel, it isn't adding to the frame for some reason.I'm using TextPad7 and I'm using Win8.
C:UsersWindows 8Documentsswing.java:42: error: '(' or '[' expected
frame2.add(panel);
^
C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression
frame2.add(panel);
[code]....
I would also like to point out that some of the comments are out of date and are referencing the way the program was before I made it just like his. For example I know my second class isn't inheriting the first class.
View Replies
View Related
Apr 27, 2014
How can I get all XML branches using JAVA. For example if i have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='test.xsd'>
<address>
<name>Joe Tester</name>
<street>Baker street 5</street>
[Code] ....
The output will be :
addresses
addresses_address
addresses_address_name
addresses_address_street
addresses_person
addresses_person_name
addresses_person_age
View Replies
View Related
Sep 19, 2014
I have developed a Java GUI by using Netbean. The user interface will get the user parameters that are needed by a c++ program (which I also developed). Upon clicking the run button java will execute the c++ program with the inserted parameters by launching and X-term session (using Runtime.getRuntime().exec(command) ) . Everything works fine in this way. However I do not find very elegant to launch an external terminal to run the C++ code. Is it possibile to have a terminal that is integrated within the java GUI? And run the C++ code within it?
Moreover, since the C++ code may take several hours to finish the job is there a way to read its output and use it in order to make, for example, proceed a progress bar?
View Replies
View Related
May 30, 2014
Using java to access SAP? I want to create a UI to analyze SAP data and create JTable reports. Not finding much on the internet.
View Replies
View Related