i now learning Object Oriented Programming but stuck. Need help. Below is the code. - PanelOption.java
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
import javax.swing.event.*;
-
-
public class PanelOption extends JPanel
-
{
-
//some code
-
-
public PanelOption()
-
{
-
createOptionGUI();
-
}
-
-
public void createOptionGUI()
-
{
-
//some code
-
}
-
-
public class ButtonListener implements ActionListener
-
{
-
public void actionPerformed(ActionEvent e)
-
{
-
if (e.getSource()==jbtnEnter)
-
{
-
PanelQuestion.Question01(); // <= i wan to access to this void method but fail! How to solve?
-
-
}
-
}
-
}
-
}
-
-
//======================================================================
-
-
PanelQuestion.java
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
import javax.swing.event.*;
-
-
public class PanelQuestion extends JPanel
-
{
-
//some code
-
-
public PanelQuestion()
-
{
-
createQuestionGUI();
-
}
-
-
public void createQuestionGUI()
-
{
-
//some code
-
}
-
-
public void Question01()
-
{
-
//some code (this is the void method that i want to invoke by PanelOption.java)
-
}
-
}
16 2440
i now learning Object Oriented Programming but stuck. Need help. Below is the code.
PanelOption.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class PanelOption extends JPanel
{
//some code
public PanelOption()
{
createOptionGUI();
}
public void createOptionGUI()
{
//some code
}
public class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==jbtnEnter)
{
PanelQuestion.Question01(); // <= i wan to access to this void method but fail! How to solve?
}
}
}
}
//================================================== ====================
PanelQuestion.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class PanelQuestion extends JPanel
{
//some code
public PanelQuestion()
{
createQuestionGUI();
}
public void createQuestionGUI()
{
//some code
}
public void Question01()
{
//some code (this is the void method that i want to invoke by PanelOption.java)
}
}
Hi xirowei, welcome to TSDN,
create an object of type PanelQuestion -
PanelQuestion pq = new PanelQuestion();
-
then call the the method
all non-static methods must be perfixed with an object.
good luck
Consider the following scenario: my name is Jos, I'm an instantiation of the
class SillyPerson. You can tell me things: -
public void tell(String message) {
-
...
-
}
-
If you want to tell me something you have to do this: -
SillyPerson jos= new SillyPerson();
-
jos.tell("you are silly");
-
and the message would be sent to me.
You can't just do this: -
SillyPerson.tell("you are silly");
-
because you are talking to an instance of the class SillyPerson (e.g. me) not
to the class, the blueprint of all silly persons. In other words: you need at least
an instantiation to talk to.
kind regards,
Jos
Consider the following scenario: my name is Jos, I'm an instantiation of the
class SillyPerson. You can tell me things: -
public void tell(String message) {
-
...
-
}
-
If you want to tell me something you have to do this: -
SillyPerson jos= new SillyPerson();
-
jos.tell("you are silly");
-
and the message would be sent to me.
You can't just do this: -
SillyPerson.tell("you are silly");
-
because you are talking to an instance of the class SillyPerson (e.g. me) not
to the class, the blueprint of all silly persons. In other words: you need at least
an instantiation to talk to.
kind regards,
Jos
Indeed welcome to TSDN. As you can see we have all sorts of people here. Now you see how your code looks under code tags? So next time you post code just wrap it inside code=java tags. the tags go inside square brackets []
As you can see we have all sorts of people here.
No we don't: -
Collection<SillyPerson> TSDN= new ArrayList<SillyPerson>();
-
kind regards,
Jos ;-)
epots9 thank you very much. You guide is really simple and easy to understand. Now it solve my problem of the non-static problem.
epots9 thank you very much. You guide is really simple and easy to understand. Now it solve my problem of the non-static problem.
Well the SillyPerson example really looked good too. It told quite a lot of true things which you would have done good to notice.
i won't disagree with u there r035198x, but still
:-)
kind regards,
Jos
- TSDNAdmin nonSillyPerson = TSDN.getAdmin();
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
nonSillyPerson.ban(silly);
-
System.gc();
-
}
-
}
- TSDNAdmin nonSillyPerson = TSDN.getAdmin();
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
nonSillyPerson.ban(silly);
-
System.gc();
-
}
-
}
lol, that was good
lmao
- TSDNAdmin nonSillyPerson = TSDN.getAdmin();
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
nonSillyPerson.ban(silly);
-
System.gc();
-
}
-
}
Ha! Code war! - TSDNAdmin nonSillyPerson = TSDN.getAdmin();
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
nonSillyPerson.ban(silly= null);
-
System.gc();
-
}
-
}
kind regards,
Jos ;-)
Ha! Code war! - TSDNAdmin nonSillyPerson = TSDN.getAdmin();
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
nonSillyPerson.ban(silly= null);
-
System.gc();
-
}
-
}
kind regards,
Jos ;-)
- public boolean ban (SillyPerson silly) {
-
if(silly == null) {
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
silly.defenestrate();
-
}
-
}
-
}
-
else {
-
silly.defenestrate();
-
}
-
System.gc();
-
}
-
- public boolean ban (SillyPerson silly) {
-
if(silly == null) {
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
silly.defenestrate();
-
}
-
}
-
}
-
else {
-
silly.defenestrate();
-
}
-
System.gc();
-
}
-
Ha! simple stuff: - public boolean ban (SillyPerson silly) {
-
if(silly == null && silly != null) {
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
silly.defenestrate();
-
}
-
}
-
}
-
else {
-
(silly= r035198x).defenestrate();
-
}
-
System.gc();
-
}
-
kind regards,
Jos ;-)
Ha! simple stuff: - public boolean ban (SillyPerson silly) {
-
if(silly == null && silly != null) {
-
for(SillyPerson silly : TSDN) {
-
if(silly instanceOf Jos || silly instanceOf epots9) {
-
silly.defenestrate();
-
}
-
}
-
}
-
else {
-
(silly= r035198x).defenestrate();
-
}
-
System.gc();
-
}
-
kind regards,
Jos ;-)
Incompatible types: found TSDNAdminNonSillyPerson required, SillyPerson (Jos)
Incompatible types: found TSDNAdminNonSillyPerson required, SillyPerson (Jos)
Duh: -
public interface Defenestratable {
-
public void defenestrate();
-
}
-
...
-
public class TSDNAdminNonSillyPerson implements Defenestratable {
-
...
-
}
-
kind regards,
Jos ;-)
Duh: -
public interface Defenestratable {
-
public void defenestrate();
-
}
-
...
-
public class TSDNAdminNonSillyPerson implements Defenestratable {
-
...
-
}
-
kind regards,
Jos ;-)
Argh, alright I give up. I'm cooked. There should not be allowed a reasonable implemention of the defenestrate method.
Next time I'll choose the pink axe first ...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bjam |
last post by:
Hi, if I want to include a set of call template methods into my xsl
file can I do that? Meaning I want to have the template method below
of data_output in another file that I can use in several...
|
by: Julius Mong |
last post by:
Dear all, if I have something like this:
<html>
<body>
<embed src="..." id="svgPage" />
</body>
</html>
and I did this in the same doc:
|
by: JJ |
last post by:
Hi,
usually, I'm not using MS servers, but I have a big problem with a
Access table.
I should create a web application for a Historical Dipartment.
They have created a populated a Access...
|
by: stu |
last post by:
I have several databases that are opened using various versions of
Access and VB. Up till recently everything worked fine, then I started
getting a variety of lock file error messages, both on my...
|
by: Markus Svilans |
last post by:
Hi,
I have a weird problem in a virtual method. The original method code
raises an access violation when it is run. The solution to the problem
is to declare a dummy integer inside the virtual...
|
by: thread |
last post by:
Hi All
i'm building a database in access and i want to restrict permissions.
from the access i can just limit the posiblity to unhide an hidden
table and in this way i can preventing the users...
|
by: jpr |
last post by:
I have 2 classes saved as 2 different java files.(eg- class ABC.java & PQR.java)
->ABC.java
classABC extends JTextField
{
ABC(int i)
{
super(i);
...
|
by: bsonline |
last post by:
I have to modify a .java file in a project. But I dont have any editor to compile java. I use putty to connect server(Solaris). And using putty console I modify .java file and save it. Then I down...
|
by: manjava |
last post by:
I have a problem in my method I know how to continue to find the shortest distance and then extract cinques the nearest distance method must return cinques longitudes and latitudes with their cities...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |