Warning On Class With JFrame Inheritance (extends)
Sep 2, 2014
I'll start off by showing my full code:
Main class
import javax.swing.JFrame;
public class groupingTest {
public static void main (String[] args) {
groupWindow test = new groupWindow();
[Code]....
At the start of the groupWindow it turns yellow and it says "The serializable class groupWindow does not declare a static final serialVersionUID field of type long".
View Replies
ADVERTISEMENT
Nov 4, 2014
I have two classes in two different files.
Color.java and Light.java
The Color class:
public class Color {
private int red;
private int green;
private int blue;
public Color(){
red = 0;
green = 0;
blue = 0;
}
And i have the Light class :
public class Light {
private Color color1;
private boolean switchedon;
public Light(int red, int green, int blue){
//dont know what to write here . how can i use the members of the Color class here ? without using extends.
}
}
View Replies
View Related
Mar 25, 2015
I am trying to redefine the FileNotFoundException by creating a new class which extends it, but I am having difficulty. For my class practice, if no file is selected or passed in, an UnknownFileException should occur.My code is the following:
Java Code:
import java.io.FileNotFoundException;
public class UnknownFileException extends FileNotFoundException {
public UnknownFileException() {
super("We couldn't tell what file this is");
}
public UnknownFileException(String message) {
super(message);
[code]....
But I get a compile error stating an unreported FileNotFoundException.
View Replies
View Related
Apr 8, 2015
I'm building a text editor. At this point, the editor should be able to read and write text and rich text. I create an instance of a RichTextEditor class that I created that extends a superclass I created (that extends JTextPane). Both my rich text and plain text classes extends the superclass I created. I use the this.read() to input my plain text from buffered reader. I think I need to use the read(fileinput stream, rtf document) method from type RTFEditorKit, but I cannot use that because it does not extend RTFEditorKit. I don't want to create a new class that extends RTFEditorKit because I need stuff from the JTextPane.
here are the classes on git... the super: TextEditorPane.java
The plaintext: TextEditorWrap.java
and the rich: RichTextEditor.java
I have fiddled with the read() method in different ways. In all cases, nothing loads. If I use the BufferedReader method, it doesn't give me an RTF, just the code for the RTF file.
How should I proceed? Do I create some sort of RTF interface and implement it?
View Replies
View Related
Mar 15, 2014
I am working on a project where i need to show a year value in a class that extends JSpinner.Its working just fine but when i try to set an alignment value for the editor textfield it all falls apart and i know im missing something really critical here but i can't see or find it all i know is that i can't make a proper reference to the textfield component in the editor i use in the correct way or aproach.
public class JNumberSpinner extends JSpinner {
private String actionCommand;
private boolean isEnabled;
private int startValue;
private int columns;
private int alignment;
private SpinnerNumberModel model;
private JSpinner.NumberEditor numEditor;
private JFormattedTextField jTxtEditorView;
[code]....
View Replies
View Related
Mar 1, 2015
Does child class gets a copy of the methods and variables of parent class?
public class test1 {
public static void main(String a[]) {
Child c = new Child();
c.print();
[Code] ....
why is the output 1?
View Replies
View Related
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
Sep 26, 2014
Here is my abstract Boat class.
public abstract class Boat{
private int height;
private int length;
private int width;
private double boatValue;
private double chargeRate;
private Owner owner;
public Owner getOwner() {
return owner;
[Code] ....
View Replies
View Related
Oct 9, 2014
This is my main.java:
import javax.swing.UnsupportedLookAndFeelException;
public class Main
{
public static void main(String[] args)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
{
Core window = new Core("GAME1", 0, 0, true, true);
}
}
And this is my Core.java:
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
[Code] ....
In Core.Java at line 80 how can I access window (
JFrame window = new JFrame(Game_Title); // <- this window
) ?
Also should I use throws or try and catch ?
View Replies
View Related
Apr 23, 2014
we're working with classes and interfaces and we see like this;
class class1 extends class2 implements interface1 { }. //it is valid
I want to know that why we cannot implement an interface before extending a class like this;
class class1 implements interface1 extends class2 { }. //it is invalid
View Replies
View Related
Oct 9, 2014
I would like to pass a variable I have in my main to my JFrame. In my main I calculate which pictures I should show in my JFrame. Is it possible to make objects of these pictures in my main class and use them in my JFrame? something like my code below.
public class JFrameTesting {
public static void main(String[] args) {
Image ImageVariable = Toolkit.getDefaultToolkit().getImage("C:1.jpg");
MyJFrame f = new MyJFrame();
f.setTitle("Drawing Graphics in Frames");
[code]....
View Replies
View Related
Jul 16, 2014
I have one question that suppose I am designing a Swing applications and I am using JFrame as Top level container.
So what is best
1)first Extends that class like
public class A Extends JFrame
{
//Do all stuff with Top Level container with gui
}
2)Or design like this from this source
[URL] ....
package components;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* TopLevelDemo.java requires no other files. */
public class TopLevelDemo {
/**
* Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
[Code] .....
View Replies
View Related
Mar 26, 2014
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
/* display selected number
if selected, bg is green
if not selected bg is pink
*/
[code]....
my compiler is telling me that the getList... method is not being overridden.but when I change the JList<String> to JList and Object to String in the parameters, i get a warning from the compiler that it's an "unchecked call".
View Replies
View Related
Apr 19, 2014
I have a jFrame and a Java Class. Now i have a path of image in my jFrame which I want to display in java class(Crop2). I created an object in jFrame
Crop2 d=new Crop2();
and then I'm trying to send the data to the class file but it is not working.
View Replies
View Related
Apr 3, 2015
Right so I have my ItemsPage Jframe Class and I'm trying to pass my TotalPrice variable to my CashPay so I can calculate the change. CashPrice runs and works but when I try run ItemsPage it does nothing I don't even get errors. I tried to remove that small section of trying to pass the variable to CashPay and it worked perfectly so I 100% know that's the problem. This section "public ItemsPage() { Pounds = ""; //super();
Scanner sc = new Scanner(System.in);
CashPay sendTotalPrice = new CashPay();
//System.out.println("Enter your amount");
TotalPrice = sc.nextDouble();
sendTotalPrice.printTotalPrice(TotalPrice);
"
Here is complete code for both classes, I'm using GUI builder.
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
[code].....
View Replies
View Related
Nov 26, 2014
I am making a simple battleship program, you have the menu and click Start to get the board with the bombs (4 buttons as of now) Each button has either a bomb or a defualtbutton. I created my button so it can't be unselected. The problem is I have the button in a Class.java and I want that to close in a period of time. What do you recommend using?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagLayout;
[code]....
I can call the clas in my main jFrame but I want to close the class after a certain time.
View Replies
View Related
Feb 4, 2014
I am working with a program where I am required to use a JFrame in a child class. The only way that I know how to access a JFrame is to do, example (public class Example extends JFrame), but since it is already extending the parent class, I am kind of stuck. I do not think that you can extend two separate classes, so..... I am stuck.
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 22, 2015
Why java uses the keyword extends when setting the bound of a type parameter(Generic) to an interface. I think using the keyword implements is more intuitive.
public static <T extends Comparable<T>>
why use extends? and not implements.
int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)
if (e.compareTo(elem) > 0)
++count;
return count;
}
I know if I want to set multiple bounds I will use extends keyword, and I will concatenate the bounds using & operator.
Is this a design decision to always use extends keyword to set bounds?
View Replies
View Related
Jan 3, 2015
What does this error mean, and also, when I get it, the command line hangs so that I can't do anything else (Is there a way to recover from that?). I'm running Windows 7.
Jan 03, 2015 5:00:59 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node SoftwareJavaSoftPrefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
View Replies
View Related
Jun 12, 2014
When I run the following code from Java HeadFirst, everything goes fine but along with one error ( i don't know is it an error or exception, or some other windows stuff). The code is
import javax.sound.midi.*;
class ExceptionHandling {
public static void main(String[] args){
ExceptionHandling o = new ExceptionHandling();
o.play();
[Code] ....
And what I got on cmd ( I am using Windows 7) :
Jaspreet javac ExceptionHandling.java
Jaspreet java ExceptionHandling
Jun 11, 2014 5:19:40 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node SoftwareJavaSoftPrefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
We got the sequencer
What is meant by code in blue? I know its some message from windows os and not from jvm. but i didn't understand it.
View Replies
View Related
May 18, 2014
public void init(Board board) {
JPanel Panel = new JPanel();
Panel.setLayout(new GridLayout(board.getWidth(), board.getHeight()));
getContentPane().add(Panel, BorderLayout.CENTER);
Panel.setBorder(new LineBorder(Color.BLACK)); // it does not work also
[code]....
I have a JFrame. I added two JPanels to the JFrame. The first one is GridLayout and it should be situated at CENTER. Another one is bottomPanel, and that one should be situated at SOUTH.I would like to add two new JPanels(kit and another one) to the bottomPanel.Compiler does not show any warning or errors.The problem is, that bottomPanel situates at NORTH, not at SOUTH. kit situates at CENTER of bottomPanel, not at WEST.
View Replies
View Related
Mar 26, 2015
There are 2 methods and a main one. The first is a void that creates a 3x4 2d array and the second is to search for a value in the array, if found it will return the number of the row that contains that value. If not, it will return -1, but I am getting 1 error and 1 dead code warning.I will put comments at the lines that contain the problems
import java.util.Scanner;
class Question4{
public static void main(String[]args){
Scanner s = new Scanner(System.in);
int x,n;
System.out.println("Please input the value that will be used in the array");
x=s.nextInt();
System.out.println("What is the value you want to search for?");
n=s.nextInt();
createArray (x,n);
[code]....
View Replies
View Related
Jan 29, 2014
I'm working on a program using GUI. My problem is that I'm reaching **1000 Line** and this is stressful because all my code are in one file. I'm not liking this. So I research the internet about Inheritance. However, what I know about Inheritance that Inherit everything in the parent class. However, when I try to use a variables in the child class to override it in the parent class I can't for example let say that I have in the parent class something like this:
JButton getButton = new JButton("Enter");
Now when I go to the child class. I want to Inherit and use this variable so I can use the ActionListener on the getButton and override for the parent class, but it's not working.
This is my code:
public class H_Store extends JFrame {
private String s ="Kinds: ";
private JButton calculateButton;
private JPanel mainPane;
private JPanel getProfitPanel;
private JTextField ground_M_QTextField;
[Code] ....
What I want to do exactly is to take the last code into another class or do something with it so I can use it in the Parent class, in other word any math calculation method or class I want them outside the Parent class. I mean this code :
private class CalcButtonListener implements ActionListener{
// vairbles for the ground Meat check box
private double total_GM;
private double weightPrice_1;
private String stringQ;
private String stringW;
private String stringP;
[Code] ....
View Replies
View Related
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
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