Swing/AWT/SWT :: GUI - Create User Interface That Interacts With Setters And Getters Of Some Classes
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.
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. ?
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.
I am trying to create a basic graphical user interface for sequence translation (including a JTextField for the description of a sequence and status of function button pressed e.g. “simple” translation and input and output TextFields). This involves a number of different class files. I cannot get my user interface to do what I want and I think I have problems with my "actionPerformed" method. How the code should be linked together?
public void actionPerformed(ActionEvent event) { try { // Get the description, content and result String d = tool.getDescription(); String input = tool.getInputText(); Stringr = translation.getResult();
create an application following the MVC pattern. My frame is composed of a JTable with some JComboBox and classic next/previous buttons to page the table. The table shows data of current accounts of the members of a family. My problem is figuring out how the controller interacts with the view, for example to enable / disable buttons or reset and reload the data in the comboboxes. In the view class all the graphical components are private instance variables. What is the best approach to ensure that the controller can act on them?
I need to create in the view public methods to act on each component like getSelectedItemAccountCombo, getSelectedItemYearsCombo, getSelectedItemMonthCombo, populateAccountCombo (ArrayList <String> list), setNextButton (boolean b) ... and so on (I think that the methods would be many ...) This approach does not convince me because I think that the class is fouled by procedures that should be in the controller class.
I have a database containing products which are separated in categories and subcategories.I want to create a user interface that will allow the customer to select any category or subcategory and load the products in the main application window.My problem is that i dont like tree do you know any alternative of tree that i can use ?
What I'm trying to do is show a loginscreen. After logging in it should show another contentpane with actual content.
This is my main class:
public class Project extends JFrame { public static void main(String[] args) { JFrame frame = new Project (); JPanel paneel = new Paneel (); frame.setSize (800, 600);
[Code] ....
The compiler gives me an error when I try to refer to "frame". What I've tried to do is refer to frame by using Project.frame but it still gives me the same error. The compiler shows the message that it cannot find "frame" in class Project, but that's exactly where it is!
Is there a simple way to make this work? I've read about threads and loops but they don't seem the most basic solution. Maybe there's a way to get the current frame so I can use that?
I have the following code that will make linked list and order its elements using self referential objects. but i have the following error: incompatible types
required: ListNode<T#2> found: ListNode<T#1> where T#1,T#2 are type-variables: T#1 extends Comparable declared in method <T#1>insertInOrder(T#1) T#2 extends Comparable declared in class OrderedList
import java.util.*; public class ListNode<T> { ListNode<T> nextNode; T data; public ListNode(T item) { this(item, null);
why don't I define my methods in a class, rather than going a level up and declaring it first in an abstract class/interface? If the point is to have different implementations for different needs, then we have the option to override the methods.
I am new to Java, and last week had an assignment to create a shopping list. I made it so that I have one class use a ProductData class to load an array of objects (description, price, priority). This week I need to take that program and change it so that it includes an Interface and Abstract Class. I need to also split one class up into at least 2 others.
I am having trouble getting my thoughts together and figuring out what to put in the interface and what to put in the abstract class. I'm thinking that it might be best to split up the ProductData class up into 3 different classes: description, price, and priority. Then have an interface with a print method. Each of those 3 classes will implement the interface.
As for the abstract class, have the price and priority extend the abstract class. The abstract class will be at the same level as the interface and contain the set and get methods. Right now they are of 2 different data types: int, double. Should I make both of them Double, and then use a method to change the priority to an int?
Should price and priority inherit from description, or should they all be at the same level? I am thinking that they should be at the same level because they all describe the item in the array.
My most confusing part is that I have no clue at all on how I can load that array when each object is split up in a different class. My professor went over ArayLists last week, and we can now use them if we want, but the assignment doesn't explicitly say that we should change it to an Array List. Where does the constructor for the ProductData() go? Do I split it up into 3 different constructors?
If I lets say have an interface Animal, and I create a lot of classes with a different animal name that implement the interface Animal. Then I create an ArrayList of Animal. Then I would put in lets say Dog class into the ArrayList, which has custom methods and data that the Animal Interface doesn't have, is this data ripped away except for the methods that are put in the Animal interface? So if I would cast the Animal back to Dog, would it retain all the data that existed before it was placed in the ArrayList?
I am writing a game in Java for Android (although my question isn't Android or Game Dev specific).
I have a SceneManager class and a Scene interface and then various other classes that implement the Scene interface (Code at the end of this post).
Basically, in my MainGame class (which also implements the Scene Interface for Touch Event capturing purposes) I hold the bulk of my game code. Methods in this class are then called from my Level classes. (most of these are needed in all levels so it makes sense to hold them here and call them from the levels to eliminate unnecessary code duplication)
So, I have Level1, Level2......... Level20 classes which all implement Scene.
Now, the problem comes because in only 2 of my Levels something can happen (that can't in the other 18) and I need to run a response method in these 2 levels (the method isn't exactly the same, the response to this event happening is different for both levels).
To run common methods from my classes, I use my Scene Manager like this:
This works great as all Level's have an updateLogic(); and render(); method.
So from my mainGame class, I am doing something like : (pseudo code)
public void checkIfSomethingHappened(){ if (something happens){ if (currentLevel==5){ Level5.response();}
[Code]....
The above would be called from my 2 level classes. So something like:
MainGame.checkIfSomethingHappened(); //Called in addition to the normal methods that make up that level
I don't really want to have this (second) 'if' statement here in the middle of my performance critical game loop.
What I'm after is something like this:
if (something happens){ SceneManager.getInstance().getCurrentScene().response(); }
However, this would require me to put stubs in the other 18 classes.
I'm thinking there must be a way to do this as the SceneManager already knows the current scene so it seems a waste checking it again via an if (or switch) statement. What is the best way to do this without having to put stubs into classes that don't require this method?
I know that we can create an inner class inside an interface but i want to know that why we'll create an inner class inside an interface. I mean what is the use of creating inner class inside an interface and what is the advantage of it.
I am making an app that would allow user to buy seat either by Price or Choice (Row and Column). I have Original code where it runs within JAVA IDE I am making same thing but rather in GUI now. I need putting my Buttons, textfield, and area in organize fashion.
I have not explain how these buttons will behave or act but right now putting them in order is priority then I will add action listeners to do the task we intend to do. A Wire Frame of the code looks like this :
I need to create and simulate an ATM interface for my computer programming class using scanner class, if else & switch statements. I've been working on this assignment all day and I'm still no closer to figuring out how to do it. I'm currently working in NetBeans to try and solve it. I have attached the pdf , what I need to do. This is what I have so far:
package bankatmifelse; //Gator Bank ATM Program import java.util.Scanner; public class BankATMIfElse {
//create line Point beginOfLine = new Point(point1, point2); //ask user for second pair of coordinates System.out.print("Enter the coordinates for X2 or <Random> or <Exit>:"); userInput=keyboard.nextLine();
code part to another class but nothing..this is what a second class should be doing
1 - Write a java class called Point to represent a 2-D point (With x and y)
- The constructor should take the x & y as double
- The class should have accessor / mutator methods for all coordinates
2 - Write a java class called Line to represent a line (with a starting point and an ending point)
- The constructor arguments are the start and end points
//import utilities to be used in the program import java.util.Scanner; import java.util.Random; public class Point { //declare variables private double pointX, difX; private double pointY, difY;
I'm trying to get to grips with the AndEngine, so I've recently gotten hold of their Cookbook, but there's a section that's confusing. I'm using the Eclipse IDE with the section is asking that I create two inner classes to an ObjectFactory class. I'm not sure if what it wants me to do is doable in java or specifically in Eclipse. This is the section of code the book is asking me to create.
Java Code:
package com.example.helloworld;
public class ObjectFactory { public static LargeObject createLargeObject(final int pX, final in pY){ return new LargeObject(pX,pY); } public static SmallObject createLargeObject(final int pX, final in pY){ return new SmallObject(pX,pY); } } mh_sh_highlight_all('java');
Now this is returning errors that I should declare these two as individual classes, but I feel like I am missing something. Earlier the book asks you to create this BaseObject class.
Java Code:
package com.example.helloworld;
public class BaseObject { @SuppressWarnings("unused") private int mX; @SuppressWarnings("unused") private int mY;
[code]...
It then mentions that the two classes LargeObject and SmallObject are inner classes of BaseObject and extends this class. The ObjectFactory class is meant to determine which subtype of the base class that needs, as well as define the objects properties.
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?
For class, we need to create a word game using classes and objects.
The game is played in rounds. The player is presented with a word that is missing letters. The player has to fill in the missing spaces with their letter guesses. The words presented are chosen with a random number generator which has been provided for us. At the end of the game, the player is shown their score.
In steps, I have to:
-Welcome the player. -Present the puzzle. -Allow the player to fill in the blanks. -Have the program check responses for correct/incorrect input. -End the game if they have three misses, or continue if they complete the puzzle.
Now, to start, I have a class for the number generator, a class to store the array of 25 words, and a class for the game itself.
I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.
Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
Any Technique that will decide which one of the fields (Integer, Address, DOB, String, Float) are user defined type. (An outsider class should used that will identify the Java classes and the user-defined classes.)
I am making an expert system using Jess about animals. I wanted to make an interface using Swing and so I did. I have a problem using group layouts. The application works fine but at the end a exceptions is thrown:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0, alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=, preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING, horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=, text=The animal is a cheetah.,verticalAlignment=CENTER, verticalTextPosition=CENTER] is not attached to a horizontal group
[Code] ....
The application ask the user some questions about the animal. When the expert system has enough information to know the animal it tells the name of the animal and shows a picture of it. The exception is thrown when the application has guessed the animal and shows the response.
I'm trying to create a Java swing chess application, but would like to divide the GUI part of it into at least two different classes (possibly more later, but I'm not sure yet). Currently I have a mainGUI class and a ChessBoard class, both of which extend JFrame. I want the main GUI class to contain a JPanel which will house several components, including a JPanel originating from the chessboard class that contains the actual board.
Is there any way to do this? I tried just creating a ChessBoard object in my main GUI class and then adding it to the component, but I got an illegal argument exception, because apparently you can't add one JFrame to another. How to do what I'm trying to do, or just how to split GUIs into multiple classes in general?
In the book we made a GUI which has 2 buttons, a label and a panel (the panel is a subclass of JPanel). What the program does is the following: When I press one of the two buttons, in the panel there is a rectangle that changes its color. When I press the other button it has to change the text on the label. Now the problem is that when I start the program, the FIRST time I press the button on which the label must change, this also changes the color in the rectangle, which it should not (I also noticed that when i FIRST click the rectangle shifts a little bit to the left). After that the program works fine.
Im writing a program that records the score in a dart game. One component of the program is a stage where players enter their name.This information needs to be displayed in another part of the program. These two components are in two different classes. My problem is I dont know how to get that information from one class to another.
Im using Jtextfield in Jframe to record the information.