Swing/AWT/SWT :: Extending Classes And Importing Libraries Basics?
Mar 12, 2015
1. Tried to use setLayout() but it wouldn't let me. Have imported libs
import javax.swing.*;
import java.awt.*;
but it doesn't work. It only worked when I extended a class with JFrame. Why do I have to do it? I already have a JFrame instance:
public test(){
JFrame frame = new JFrame();
frame.setTitle("Workshop");
frame.setBounds(500,300,400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
....
}
This code runs smooth, so it's confusing for me that it lets me create a JFrame object, and put buttons onto it, but it wants me to extend the class onto JFrame class in order to use a method.
2. I've read somewhere that AWT is old and should not be used anymore. Is there a diagram or a list with objects and properties that are manipulated only by Swing so that I could concentrate only on those? For example (made up list):
JPaper -
- width, setWidth(x)
- height, setHeight(x)
- position, setPosition(x,y)
- color, setBackground(RGBa)
- acquire, add(subordinate component)
- deprive, remove( subordinate comopnent)
- etc...
JSticker -
- width ...
- height ...
- write, setText(String)
- etc...
View Replies
ADVERTISEMENT
May 5, 2014
I have been working on project (developing web interface for generating dynamic reports)for that i have downloaded dynamic reports library and i want this library to be imported for my project to jsp page on netbeans 7.2 how can i do it?
View Replies
View Related
Dec 10, 2014
I'm currently using TextPad or command prompt to compile and run my programs, and as usual I am not having any luck importing external libraries, in particular apache commons.
I couldn't see any particularly obvious settings in TextPad to set a library or class path (which is annoying as I really like the program), so I jumped back to cmd prompt to run it from there. Aaaaaand i don't understand .
This is my file structure at present:
/mainProject //includes .java and .class files, and where I've successfully placed .jar files before.
The apache commons zip file was extracted here, making:
/mainProject/commons-lang3/apidocs/orgs/apache/commons/<folders> //the commons-lang3 folder contains the jars I'm navigating to the /mainProject folder in cmd prompt and typing (amongst many other things) javac -cp /mainProject/commons-lang3 MonsterGame.java //with the -cp being pointed at the folder the .jar is in i've tried pointing it at the root folder where the import statement begins in the code (ie mainProject/commons-lang3/apidocs), tried moving the .jar files to the mainProject folder (pointing -cp at it) and more. No luck.
it seems everytime i try to import a new library something goes wrong..... its become a bit of a stumbling block to be honest. I seem to spend most of my time dealing with the 'administrative' side of coding (that was the politest way i could put it ), am I not doing it right?
I've read I'm supposed to include the .jar in the classpath, not just the directory. is this correct? (it still doesn't work...!)
View Replies
View Related
Jan 30, 2015
My teacher told me : It looks like everything is working except that in the Box, the method returns true if it is not a box.
The only other thing missing is the if statements in the main method using the .equals() method to do the comparisons. But, now I am lost on how to do my if statement.
HTML Code:
private int height;
/**
* Constructor for objects of class box
*/
public Box3(int l, int w, int h)
{
// call superclass
super(l, w);
// initialise instance variables
height = h;
[Code] ....
View Replies
View Related
Sep 20, 2014
Basically I want to make a class called library, but I don't want to make an interface because I actually want to define the methods. I think I can only use abstract classes but not really sure how to use those. But I still have a problem, I want to create a Map that classes implementing Library class have to have in their code, and the Map will be a HashMap with <String, ParentClassHere>, so basically let's say I make a class called Car, implemeing Library to the Car class would create a Map library = new HashMap<String, Car>. Can I do something like this? And also include methods to get values and set values to the library Map?
View Replies
View Related
Jan 4, 2015
I have a working program, except that it does not calculate the credit hours and the financial aid. When I enter an input, it works, until it should show the student name, credit hours and financial aid. the error i get from the command is "Hours invalid for false student". Here is the program i think i might have the problem.
import java.text.DecimalFormat;
public abstract class Student
{
//initialise variables
String name;
int creditHrs;
[Code] .....
View Replies
View Related
Aug 19, 2014
I was wondering how Java knows where to Import classes from when we don't specify the whole directory path.
For example: import java.util.* Does It automatically search In both your current directory and the directory created during Installation that contains the standard library (wherever It may have been Installed) ?
View Replies
View Related
May 22, 2014
Let's say hypothetically you're making a huge program and use a lot of imports (ex import java.util). If you only need a few specific things from java.util, will it use more memory importing java.util.* compared to only importing lets say java.util.Scanner, java.util.ArrayList, etc. Basically does importing a whole package use more (if any at all) memory than only importing specific package parts?
View Replies
View Related
Nov 28, 2014
Lets say I am selecting a record at a time from mysql.
String sql = "SELECT id, first, last, age FROM Registration";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
[Code] ....
The code above selects the data that i need.Now,i want to have this in some sort of a thread.This is what i want to achieve.
The code displays a record a time,i want to introduce sleep for 10 seconds before displaying the next record.Before going to the next record,i want the program to check whether a condition is true such as the value of a field of a table being 1 or 0.
If the condition is not true(therefore is false),i want the program to display 'waiting.....' and should continue waiting until the condition is true.
View Replies
View Related
May 17, 2014
I want the text that the user inputs into the JTextField in the user input panel to be what shows up in the JTextField in the totals panel.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.*;
import javax.swing.border.TitledBorder;
[Code] ......
I know that I will need to take advantage of the get and set methods, could I get an example of this? How to write the code.
View Replies
View Related
Sep 12, 2014
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?
View Replies
View Related
Feb 19, 2014
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.
Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TwoButtons{
JFrame fr;
JButton labelButton;
JButton colorButton;
JLabel label;
[Code] ....
View Replies
View Related
Apr 8, 2014
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.
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
Jul 25, 2014
Really need some simple and complete example on how to extends components (graphically and functionally) for primefaces 5.
For example I can't figure how to add custom attributes to existing component or define default values for existing attributes.
Is there any tutorial or a basic common way to achieve this goal or each component have to be extended in its way?
View Replies
View Related
Oct 21, 2014
I am writing a program that should take a url and scan the page for any links. It is in the beginning stages, but I ran into an error when I tried to extend a class. There's a lot going on in this code, but the error is caused by the constructor.
Error message at compile time:
"constructor Page in class Page cannot be applied to given types;
{//Constructor
^
required: String
found: no arguments
reason: actual and formal argument lists differ in length".
Here's the code(first my class, then the class I extended)
public class SearchEngine extends Page {
public static Color customGreen = new Color(69, 194, 33);
public static Color customYellow = new Color(232, 166, 12);
public static Color customBlue = new Color(25,97,255);
public static Color customYellowComp = new Color(178,125,0);
[code]...
View Replies
View Related
Apr 10, 2014
Java Code:
public class Game extends Canvas implements Runnable, KeyListener {
private static final long serialVersionUID = 1L;
public Game() {
setMinimumSize(new Dimension(width, height));
setMaximumSize(new Dimension(width, height));
setPreferredSize(new Dimension(width, height));
}
[code]...
I want to remove the extends Canvas from the top line and when I use JFrame to add canvas, I don't do add.(this, but instead I do add a canvas variable I make. So instead of extending I want to make a variable. But then how would I do the start, stop and run?I want to use Graphics, Canvas (Not Jpanel because I want to use BufferedImage) & JFrame. I don't want to extend Canvas, how could I use Canvas identically to shown above but instead of extending using it as a variable? or, how could I do this?
View Replies
View Related
May 26, 2014
I'm having a problem with SplitPane (horizontal Flow). What I'm looking for is to find a way to maintain the left pane in the same position when the main window maximizes. I do not want the left pane to grow on its width. If I go into the AnchorPain Constraint in the Scene Builder and remove the right and left constraints, when I run the application, the left pane keeps its position, but it appears a gap between the two panes (the left pane and the right one).
I need to find the way to expand the right pane to the position where the left pane is.
The link shows an image that illustrates the problem. [URL]
View Replies
View Related
Oct 18, 2014
What is the difference between extending JFrame in one class and simply constructing a new JFrame object in that same class? What benefits do I have with each solution, providing I want to use that class to create the GUI. Is it the same or are there differences rather than not having to reference to a new JFrame to be able to use its functions?
View Replies
View Related
Feb 14, 2014
I am new to java and during my classes we built a basic calculator. I want to extend my calculator and added function to square numbers.Here is my program:
Java Code:
package calculator02;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[code]...
View Replies
View Related
Apr 26, 2014
I've been trying to pull data from another class file "Calculations.java" and have it be displayed in a TextField in "DataAnalyzerGUI.java". Here is how the hierarchy is broken down for my assignment:
DataAnalyzerGUI.java extends JFrame
ReadFiles.java extends DataAnalyzerGUI.java
Calculations.java extends ReadFiles.java
Everything displays and functions correctly in a command prompt if I use a line like this:
System.out.println ("Lowest opening " + dateArray[lowestOpenIndex] + ": " + dataArray[lowestOpenIndex][2]);
But trying to get it to display in a GUI has been quite troubling.
I know the code is supposed to look something like this:
dataOutput.setText(DESIRED CODE HERE);
But I am unable to find anything of value to work out.
I have attached my complete project....
Attached File(s)
Assignment 4.pdf (247.05K)
Assignment 4.zip (235.81K)
View Replies
View Related
Nov 30, 2014
I want to import an image to resize but not sure how to start of.Should I be using the "BufferedImage & ImageIO.read" method or the "paint(Graphics g) { Image img1 = Toolkit.getDefaultToolkit().getImage" method?
View Replies
View Related
Feb 18, 2014
I've got this annoying error message when trying to import:
import org.apache.commons.codec.binary.Hex.encodeHex;
"Import org.apache.commons.codec cannot be resolved", which after searching seems to be a somewhat common problem. The solution being to go to: FileUpload - Home and download some jar file and add it to the /web-inf/lib folder. yet the error persists even after adding the jar file in "add external jar files" and restarting eclipse.
The jar file I added is called "commons-fileupload-1.3.1.jar" which is the only one I could find in the zip file. I've searched around looking at numerous threads about the issue, several of them sadly several years old, with no success.Surely installing a library to eclipse shouldn't be this complicated?
View Replies
View Related
Aug 28, 2014
I want to import a PDF file into a database, The PDF will be pulled from an email.
The PDF file must be imported into a specific user's profile.
When the user logs into his profile the file must be visible to that person only.
View Replies
View Related
Sep 1, 2014
i am trying to calculate the number of months it takes to pay off a set amount of credit card debt given the following information: principle amount, annual interest rate, and monthly payment. How to import the formula necessary to system.out.print the answer (number of months it takes to pay off debt) ???
View Replies
View Related
May 11, 2014
When importing static members of a class. Why are they only accessible within the constructor of the calling class, and not outside of it? Here's the source code to understand my question.
package Certification;
public class ExamQuestion {
static public int marks ;
static public void print(){
System.out.println(100);
[Code] ....
View Replies
View Related