How to use a textArea in another class
Hi,
Well I'm having this problem with a project where I need to print in my main Frame some values however this values need to be in a cycle I made my textArea public and with inheritance I was able to use the textArea variable however it doesn't actually work, it compiles and everything but still doesn't draw in my textArea what is supposed to? Any help? I'm using netbeans btw.
pberardi1 wrote:
Tip:
If you show your code here, you have a better chance of someone helping you. Dont forget to post your errors and use code tags.
Good LuckThe thing is that it ain't showing an error is compiling and debugging just fine when I debug it, it even goes to the line where it should print on the textArea but it just doesn't.
Here's some code it's made to try that textArea print
import Principal.Memoria;
* @author Sveind
public class FIFO extends Memoria {
private int bloques[];
private int numRan, bloque, numConj,numBloques,m=0;
private String mapeo;
/** Creates a new instance of FIFO */
public FIFO(int numRan, int numConj, String mapeo, int numBloques) {
this.numRan=numRan;
this.numConj=numConj;
this.mapeo=mapeo;
this.numBloques=numBloques;
bloques = new int[numBloques];
dialogo.append("Wassa!!!!"+"\n"); // This is where it's supposed to print however it doesnt do it
}
Similar Messages
-
How to call a method of another class ?
Hello,
I�d like to know how to call a method of another class. I have to classes (class 1 and class 2), class 1 instantiates an object of class 2 and executes the rest of the method. Later, class 1 has to call a method of class 2, sending a message to do something in the object... Does anybody know how to do that ? Do I have to use interface ? Could you please help me ?
Thanks.
Bruno.Hi Schiller,
The codes are the following:
COMECO
import javax.swing.UIManager;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
//Main method
class comeco {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception e) {
AGORA testeagora=new AGORA();
// Code for socket
int port;
ServerSocket server_socket;
BufferedReader input;
try {
port = Integer.parseInt(args[0]);
catch (Exception e) {
System.out.println("comeco ---> port = 1500 (default)");
port = 1500;
try {
server_socket = new ServerSocket(port);
System.out.println("comeco ---> Server waiting for client on port " +
server_socket.getLocalPort());
// server infinite loop
while(true) {
Socket socket = server_socket.accept();
System.out.println("comeco ---> New connection accepted " +
socket.getInetAddress() +
":" + socket.getPort());
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// print received data
try {
while(true) {
String message = input.readLine();
if (message==null) break;
System.out.println("comeco ---> " + message);
testeagora.teste(message);
catch (IOException e) {
System.out.println(e);
// connection closed by client
try {
socket.close();
System.out.println("Connection closed by client");
catch (IOException e) {
System.out.println(e);
catch (IOException e) {
System.out.println(e);
AGORA
import javax.swing.UIManager;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.net.*;
//public class AGORA {
public class AGORA {
boolean packFrame = false;
//Construct the application
public AGORA() {
try {
Main frame = new Main();
System.out.println("agora ---> Criou o frame");
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame)
frame.pack();
else
frame.validate();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
catch(Exception e)
{ System.out.println("agora ---> " +e);
// Tem que criar a THREAD e ver se funciona
public void remontar (final String msg) {
try {
System.out.println("agora ---> Passou pelo Runnable");
System.out.println("agora --> Mensagem que veio do comeco para agora: "+ msg);
Main.acao(msg);
catch(Exception x) {
x.printStackTrace();
MAIN
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
public class Main extends JFrame {
// ALL THE CODE OF THE INTERFACE
//Construct the frame
public Main() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
public void acao() {
// C�digo para mudar a interface
Runnable setTextRun=new Runnable() {
public void run() {
try {
System.out.println("main ---> Passou pelo Runnable");
TStatus.setText("main ---> Funcionou");
catch(Exception x) {
x.printStackTrace();
System.out.println("main ---> About to invokelater");
SwingUtilities.invokeLater(setTextRun);
System.out.println("main ---> Back from invokelater");
// Aqui vai entrar o m�todo para ouvir as portas sockets.
// Ele deve ouvir e caso haja alguma nova mensagem, trat�-la para
// alterar as vari�veis e redesenhar os pain�is
// Al�m disso, o bot�o de refresh deve aparecer ativo em vermelho
//Component initialization
private void jbInit() throws Exception {
// Initialize the interface
//Setting | Host action performed
public void SetHost_actionPerformed(ActionEvent e) {
int port;
ServerSocket server_socket;
BufferedReader input;
System.out.println("main ---> port = 1500 (default)");
port = 1500;
try {
server_socket = new ServerSocket(port);
System.out.println("main ---> Server waiting for client on port " +
server_socket.getLocalPort());
// server infinite loop
while(true) {
Socket socket = server_socket.accept();
System.out.println("main ---> New connection accepted " +
socket.getInetAddress() +
":" + socket.getPort());
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String espaco=new String(": ");
JLabel teste2=new JLabel(new ImageIcon("host.gif"));
PHost.add(teste2);
System.out.println("main ---> Adicionou host na interface");
repaint();
System.out.println("main ---> Redesenhou a interface");
setVisible(true);
// print received data
try {
while(true) {
String message = input.readLine();
if (message==null) break;
System.out.println("main ---> " + message);
catch (IOException e2) {
System.out.println(e2);
// connection closed by client
try {
socket.close();
System.out.println("main ---> Connection closed by client");
catch (IOException e3) {
System.out.println(e3);
catch (IOException e1) {
System.out.println(e1);
public void OutHost_actionPerformed(ActionEvent e) {
repaint();
setVisible(true);
//Help | About action performed
public void helpAbout_actionPerformed(ActionEvent e) {
Main_AboutBox dlg = new Main_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
//Overridden so we can exit on System Close
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if(e.getID() == WindowEvent.WINDOW_CLOSING) {
fileExit_actionPerformed(null);
public void result(final String msg) {
// C�digo para mudar a interface
Runnable setTextRun=new Runnable() {
public void run() {
try {
System.out.println("main ---> Chamou o m�todo result para mudar a interface");
System.out.println("main --> Mensagem que veio do agora para main: "+ msg);
TStatus.setText(msg);
catch(Exception x) {
x.printStackTrace();
System.out.println("main --> About to invokelater");
SwingUtilities.invokeLater(setTextRun);
System.out.println("main --> Back from invokelater");
[]�s. -
Use a method from another class in another package?
How can I use a method from another class in another package?
WhiteJ wrote:
What do you mean by "new keyword?" You posted this previously:
I tried that, it seems to not be working. I want to use the constructor from the other class. I imported it, using this piece of code:
import components.FileChooser;
components.FileChoser();
Typically if I am going to call a constructor on a class called Fubar, I'd use new to create a new object:
Fubar myFubar = new Fubar();Incidently, is it a simple typo in your post or are you trying to use a FileChoser object when it should be FileChooser? -
How to use abap memory in global class
Hi experts,
I want to know how to use abap memory in global class. when i try write export and import statement its showing
error is export statement does not support in object oriented concept.
Thanks
Ramesh ManoharanHi Ramesh,
Export and import statements were not allowed to use in classes. Create a global variable in public section of that class of type of export parameter.Then pass value to the global variable of class by calling that class.
by
Prasad GVK. -
How to use temporary interface in another interface as derived table in 10g
Hi ,
Can somebody please tell me how to use temporary interface in another interface as derived table in 10g.
I have an option in odi 11g to this task.But i am working on odi 10g for my project.So that please help me to do this task.
I can able to create temporary interface in 10g ,but i dont know how to use that temporary interface in another inerface as derived table.
Thanks in Advance
Thanks,
Srikanth AA temp interface CANNOT be used as a derived table in ODI 10g.
All you can do is to drag and drop the temp interface as the source in the mapping.
PS. Please remember to assign correct/helpful points to the people who help you in the forum. -
In SQLScript, how to use EXEC to call another procedure with parameters in procedure?
Hi experts,
In SQLScript, How to use EXEC to call another procedure with input and output parameters in procedure?thanks very muchHi Sagar,
thank you! I generate another procedure with an input parameter and an output parameter in a procedure. Then i need to call the generated procedure using EXEC. Here is my code:
create procedure ftest1(out sum_num bigint)
as
begin
declare fa_output bigint;
declare v_sql_drop varchar(200);
declare v_sql varchar(500);
declare cursor c_cursor1 for select num from TABLE1;
--v_sql_drop := 'drop procedure fe';
--exec v_sql_drop;
v_sql := 'create procedure fe(in i_num bigint,out o_num bigint) as begin';
v_sql := :v_sql || ' o_num := :i_num * 2 + :i_num * :i_num;';
v_sql := :v_sql || ' end';
exec v_sql;
open c_cursor1;
for c_item as c_cursor1 do
exec 'call fe(c_item.num,o_num=>fa_output)';
if sum_num is null then
sum_num := fa_output;
else
sum_num := :sum_num + fa_output;
end if;
end for;
close c_cursor1;
end;
The underline code is using exec to call the generated procedure. But this method cannot work. Any suggestion? thanks again! -
V.Important: How to use se24 to build a class step by step: Points assured
hi all
I am new to OO based abap programming. I want to build a class using SE24 but i dont know where to put the various pieces of code in SE24.
Can anyone please provide a step by step procedure (including screenshots) on how to use SE24 to build a class using most of the features like constructor, attributes , interface , friend etc.
Documents would be more helpful as compared to links.
Points will be awarded
thanks in advanceHi,
Just follow the below givenlink. Using this you can create a class in SE24.
http://help.sap.com/saphelp_nw04/helpdata/en/b3/f4b1406fecef0fe10000000a1550b0/content.htm
I think the below document would be
a very good introduction
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/0a33479c-0b01-0010-7485-dc8c09d6bc69
See the Following Dem Program:
DEMO_ABAP_OBJECTS Complete Demonstration for ABAP Objects
DEMO_ABAP_OBJECTS_CONTROLS GUI Controls on Screen
DEMO_ABAP_OBJECTS_DIALOG_BOX Splitter Control for Screen with Dialog Box
DEMO_ABAP_OBJECTS_EVENTS Demonstration of Events in ABAP Objects
DEMO_ABAP_OBJECTS_GENERAL ABAP Objects Demonstration
DEMO_ABAP_OBJECTS_METHODS Demonstration of Methods in ABAP Objects
DEMO_ABAP_OBJECTS_SPLIT_SCREEN Splitter Control on Screen
Regards,
Padmam. -
.How to instantiate the innerclass from another class with coded eg.
How to instantiate the innerclass from another class(both for static & non static) please give me an eg with coding.
It's just a preference, but I like writing factory methods:
public class Outer {
public class Inner {}
public static class StaticInner {}
public Inner innerInstance() {
return new Inner();
public static StaticInner staticInnerInstance() {
return new StaticInner();
public static void main(String[] args) {
Outer.StaticInner si = Outer.staticInnerInstance();
Outer outer = new Outer();
Outer.Inner i = outer.innerInstance();
}Often, for me, the inner class implements an interface, and the factory method
lets you hide the implementation class:
public class Outer {
private class Inner implements Runnable {
public void run() {}
public Runnable runnerInstance() {
return new Inner();
public static void main(String[] args) {
Outer outer = new Outer();
Runnable r = outer.runnerInstance();
} -
Using a variable from another class
hello friends, I have a class with the follow variable: dbcolTempMax, and the value of this variable I need in another class, how can do to use the value of the variable...thanks
Both people above described the solution, but from the question I take it you are somewhat new to programming. Let me give you a code example which may help.
public class ClassWithVariable {
private int dbcolTempMax;
public int getDbcolTempMax() {
return dbcolTempMax;
public class SomeOtherClass {
ClassWithVariable cwv = new ClassWithVariable();
cwv.getDbcolTempMax(); // This gets the value of the variable
}Now if the variable is static, you can provide a static "accessor" method to ge the variable. This will save you the trouble of constructing an object of the class.
Cheers,
Cypher -
How to use custom password encryptor/decryptor class for jdbc connection
I am in process of migrating application from Jrun server to weblogic . In jrun we use to provide our custom class which used to decrypt the password provided in resource file as below
<username>webclt</username>
<password>AAAAAAASSSSSSSCCCCCCCCCCCCCC</password>
<encrypted>true</encrypted>
<encryption-class>com.CustomEncryptor</encryption-class>
How could i use the same class while configuring datasource in weblogic 10 server.1- By default, the jre will read the user's cacerts which runs the program.
2- You can specify another cacerts this way :
System.setProperty("javax.net.ssl.trustStore", my_trust);
For the case 1 and 2, you need to put the certificate in the cacerts.. Or,
3- You implement a custom TrustManager which, for example, accepts all certificates :
class X509TrustManagerTrustAll implements X509TrustManager {
public boolean checkClientTrusted(java.security.cert.X509Certificate[] chain){
return true;
public boolean isServerTrusted(java.security.cert.X509Certificate[] chain){
return true;
public boolean isClientTrusted(java.security.cert.X509Certificate[] chain){
return true;
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {}
and you call it in the right place in the code you wrote (SSLContext,..)
Hope it helps and deserves a duke star ;) -
How to call methods defined in another class ? is it possible?
Hi all,
I am new to using JNI, was wondering if this is possible and how I might be able to do this. I'm trying to call some set/get functions defined in a class that is not part of the class where I have my native code defined and called...
Let me explain a bit, I have a class JobElement (singular Job) that stores all the data associated with a Job, such as job name, job id, etc.
Another class JobsElement (plural Jobs) contains all the Jobs that are currently running.
The code is set up something like this...
class JobElement {
String jobID;
String jobName;
public void setJobId(String newJobID) { jobID = newJobID; }
public void setJobName(String newJobName) { jobName = newJobName; }
class JobsElement {
Date timeDateStamp;
JobElement job;
class AppRoot {
JobsElement allJobs = null;
JobElement _currentJob = null;
public native getAllJobs();
}In my native method, getAllJobs(), I essentially want to call the set functions that are defined for JobElement when filling in the information of the Job. (then finally add the JobElement to the JobsElement list)
In summary, I basically want to know if it's possible to call the equivilent of this java code from the native code??
_currentJob.setJobName(newJob)
In the native code I tried to find the setJobID method but got a NoSuchMethodError. (which is what I expected)
Thanks in advance.Hi,
In your getAllJobs(), the JNI Equiv would be JNIEnv_ClassName_getAllJobs(JNIEnv** anEnv, jobject jAppRootobj)
Since you are calling the AppRoot object's method, the jobj in the native method call will be jAppRootobj-AppRoot's instance.
What you can do is
Get the field id of _currentJob.
Get the <jobject-value of currentJob> of JobElement i.e. currentJob.
Then get the method ids of setJobID and setJobName.
Call these non-static methods on <jobject-value of _currentJob> to set the values.
I hope I made a try to help you. Please correct me if I am wrong. -
How to use once SC in Another SC, and How use one DC in another DC
Hi all,
I am new to DC and SC's concetp.
we have got two abc.sca and xyz.sca files which contains some DC's kind of the functionality. So, now we need to create new SC called MyComp.sca and i need to create one new DC caleed "display_dc" in this.
So this DC need to call the DC's which are available in the above .sca files. how to build this.
How to use once .sca file in another.
How to call dc from another sca of the dc.
how to use from one dc to another dc.
do i need to define the depency in the SLD when i am create the new SCA with using SCA files.?
REgards
VijayI will try to give you a place to begin...
SC are Software Components. Think of them as development products, like MS Word or Adobe Reader. They include sets of DCs, development components. DCs are smaller units, like programs and libraries in the SCs.
Software architects define SCs in SLD and also define two types of dependencies between them:
- build time (required to compile and build)
- runtime (required during execution)
SCs themselves are "buckets" for DCs, so dependencies between SCs describe dependencies between DCs they include. Think of that the same way as we we say "SAP Visual Admin (SC) depends on JDK (SC)". It means that swing apps of Visual admin (DCs) need java classes packaged in JDK (DCs).
This will help:
http://help.sap.com/saphelp_nw70/helpdata/EN/42/d27865d006136ae10000000a1553f7/frameset.htm
DCs interact between themselves by exposing "public parts" (SAP webdynpro terminology), allowing one DC to access objects of another DC.
Here it explained in more details:
http://help.sap.com/saphelp_nw70/helpdata/EN/62/06108b6af0264a9a5393fd787ea3c9/frameset.htm
http://help.sap.com/saphelp_nw70/helpdata/EN/3b/13d6de881a8f4daac3d28e1652a2bb/frameset.htm
I tried to explain it in asimple terms.
Hope it helped.
Regards,
Slava -
How to use different Vlans outside another gateway in sg-300 28?
dear all
how shall i use different vlans outside another gateway in sg-300 28?
Example:
vlan2 192.168.2.0/24 gateway 192.168.2.1 outside router gateway 192.168.2.254
vlan3 192.168.3.0/24 gateway 192.168.3.1 outside router gateway 192.168.3.254
should me doing in sg-300 28?
thanks.Hi Amin,
Leave the switch in Layer 2 mode
Cable VLAN2 to the to the outside router gateway 192.168.2.254 interface
cable VLAN3 to the to the outside router gateway 192.168.3.254 interface
Excuse the rough diagram
Make the port going to the outside router gateway, untagged in the vlans they will be transporting. (I am assuming that the router gateway is not vlan aware.)
IP hosts will most likely get DHCP from the router gateway. The IP hosts will then automatically send IP traffic to the router gateway.
VLAN 1 in my switch, could then be the only interface within the switch that has a IP address associated with it, for management purposes.
I can see from you post, that English is not your first language, if you want to speak to someone, you can ask a question by going to;
www.cisco.com/go/sbsc
regards Dave -
Problem using repaint() method from another class
I am trying to make tower of hanoi...but unable to transfer rings from a tower to another...i had made three classes....layout21 where all componentents of frame assembled and provided suitable actionlistener.....second is mainPanel which is used to draw the rods n rings in paintComponent.....and third is tower in which code for hanoi is available...i had made an object of mainPanel at layoout21 n tower but i m not able to call repaint from tower..gives an error : cannot find the symbol....method repaint in tower.
code fragments od three classes are:
LAYOUT21
class layout21 extends JFrame implements ActionListener
{ private Vector rod1 = new Vector();
private Vector rod2 = new Vector();
private Vector rod3 = new Vector();
private String elem; //comment
public String r22;
public boolean in=false;
public int count=0; //no of times the transfer to other rods performed
private int r3,rings; // current no of rings
private JComboBox nor,col;
private JLabel no;
private JLabel moved;
private JLabel no1;
private JButton start;
private JButton ref;
private AboutDialog dialog;
private JMenuItem aboutItem;
private JMenuItem exitItem;
private tower t;
final mainPanel2 p =new mainPanel2();
public layout21()
{ t = new tower();
Toolkit kit =Toolkit.getDefaultToolkit();
Image img = kit.getImage("java.gif");
setIconImage(img);
setTitle("Tower Of Hanoi");
setSize(615,615);
setResizable(false);
setBackground(Color.CYAN);
JMenuBar mbar = new JMenuBar();
setJMenuBar(mbar);
JMenu fileMenu = new JMenu("File");
mbar.add(fileMenu);
aboutItem = new JMenuItem("About");
aboutItem.addActionListener(this);
fileMenu.add(aboutItem);
exitItem = new JMenuItem("Exit");
exitItem.addActionListener(this);
fileMenu.add(exitItem);
Container contentPane =getContentPane();
JPanel bspanel = new JPanel();
JPanel bnpanel = new JPanel();
setBackground(Color.CYAN);
//JComboBox
nor = new JComboBox();
nor.setEditable(false);
nor.addItem("3");
nor.addItem("4");
nor.addItem("5");
nor.addItem("6");
nor.addItem("7");
nor.addItem("8");
nor.addItem("9");
bspanel.add(nor);
col = new JComboBox();
col.setEditable(false);
col.addItem("BLACK");
col.addItem("GREEN");
col.addItem("CYAN");
bspanel.add(col);
JLabel tl = new JLabel("Time");
tl.setFont(new Font("Serif",Font.BOLD,12));
bspanel.add(tl);
JTextField tlag = new JTextField("0",4);
bspanel.add(tlag);
start =new JButton("Start");
bspanel.add(start);
ref =new JButton("Refresh");
bspanel.add(ref);
JButton end =new JButton("End");
bspanel.add(end);
start.addActionListener(this);
nor.addActionListener(this);
col.addActionListener(this);
ref.addActionListener(this);
end.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose(); // Closes the dialog
contentPane.add(bspanel,BorderLayout.SOUTH);
JLabel count = new JLabel("No of Transfer reguired:");
count.setFont(new Font("Serif",Font.BOLD,16));
bnpanel.add(count);
no = new JLabel("7");
no.setFont(new Font("Serif",Font.BOLD,16));
bnpanel.add(no);
JLabel moved = new JLabel("Moved:");
moved.setFont(new Font("Serif",Font.BOLD,16));
bnpanel.add(moved);
no1 = new JLabel("0");
no1.setFont(new Font("Serif",Font.BOLD,16));
bnpanel.add(no1);
contentPane.add(bnpanel,BorderLayout.NORTH);
contentPane.add(p,BorderLayout.CENTER);
String r = (String)nor.getSelectedItem();
rings = Integer.valueOf(r).intValue();
p.draw(rings,1) ;
public void actionPerformed(ActionEvent evt)
{ Object source = evt.getSource();
if(source == start)
r3 = Integer.valueOf((String)nor.getSelectedItem()).intValue();
p.transfer(false);
t.initialise(rod1,rod2,rod3,0);
t.towerOfHanoi(r3);
//repaint();
if(source == ref)
{ rod1.removeAllElements() ;
rod2.removeAllElements() ;
rod3.removeAllElements() ;
count=0;
r3 = Integer.valueOf((String)nor.getSelectedItem()).intValue();
p.draw(r3,1);
p.transfer(true);
no1.setText(""+0);
p.trans_vec(rod1,rod2,rod3);
t.initialise(rod1,rod2,rod3,0);
System.out.println("");
repaint();
if(source == nor)
{ JComboBox j = (JComboBox)source;
String item = (String)j.getSelectedItem();
int ring1 = Integer.valueOf(item).intValue();
int a=1;
for(int i=1;i<=ring1;i++)
{ a = a*2;
a=a-1;
no.setText(""+a);
p.draw(ring1,1);
repaint();
if(source == aboutItem)
{ if (dialog == null) // first time
dialog = new AboutDialog(this);
dialog.setVisible(true);
if(source == exitItem)
{ System.exit(0);
if (source==col)
{ JComboBox j = (JComboBox)source;
String item = (String)j.getSelectedItem();
repaint();
TOWER
class tower extends Thread
{ private Vector rod1 = new Vector();
private Vector rod2 = new Vector();
private Vector rod3 = new Vector();
private int count ;
private String elem;
final mainPanel2 z =new mainPanel2();
public void initialise(Vector r1,Vector r2,Vector r3,int c)
{ rod1 = r1;
rod2 = r2;
rod3 = r3;
count =c;
public void towerOfHanoi(int rings)
for(int i=0;i<rings;i++)
rod1.add(" "+(i+1));
System.out.println("rod1:"+rod1.toString());
hanoi(rings,1,2);
public void hanoi(int m,int i, int j)
if(m>0)
{ hanoi(m-1,i,6-i-j);
if(i==1 && j==2 && rod1.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod1.remove(0);
rod2.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint(); //NOT ABLE TO USE METHOD HERE...WHY??
//z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 2:"+rod2.toString());
if(i==1 && j==3 && rod1.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod1.remove(0);
rod3.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint();//
// z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 3:"+rod3.toString());
if(i==2 && j==1 && rod2.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod2.remove(0);
rod1.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint();
//z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 1:"+rod1.toString());
if(i==2 && j==3 && rod2.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod2.remove(0);
rod3.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint();
//z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 3:"+rod3.toString());
if(i==3 && j==1 && rod3.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod3.remove(0);
rod1.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint();
//z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 1:"+rod1.toString());
if(i==3 && j==2 && rod3.isEmpty()==false)
{ count++;
//no1.setText(""+count);
elem = (String)rod3.remove(0);
rod2.add(0,elem);
//z.trans_vec(rod1,rod2,rod3);
repaint();
//z.hanoi_paint();
try
this.sleep(2000);
catch (Exception e) { e.printStackTrace() ; }
System.out.println(count+". ROD 2:"+rod2.toString());
hanoi(m-1,6-i-j,j);
MAINPANEL
class mainPanel2 extends JPanel //throws IOException
public Vector line = new Vector();
public Vector rod11= new Vector();
public Vector rod22= new Vector();
public Vector rod33= new Vector();
public int no_ring;
public int rod_no;
String pixel;
StringTokenizer st,st1;
int x,y;
public boolean initial =true;
public void paintComponent(Graphics g)
{ System.out.println("repaint test");
bresenham(100,60,100,360);
bresenham(101,60,101,360);
bresenham(102,60,102,360);
bresenham(103,60,103,360);
bresenham(104,60,104,360);
g.setColor(Color.BLUE);
while(line.size()>0)
{ pixel = (String)line.remove(0);
st = new StringTokenizer(pixel);
x = Integer.valueOf(st.nextToken()).intValue();
y = Integer.valueOf(st.nextToken()).intValue();
g.drawLine(x,y,x,y);
bresenham(300,60,300,360);
bresenham(301,60,301,360);
bresenham(302,60,302,360);
bresenham(303,60,303,360);
bresenham(304,60,304,360);
while(line.size()>0)
{ pixel = (String)line.remove(0);
st = new StringTokenizer(pixel);
x = Integer.valueOf(st.nextToken()).intValue();
y = Integer.valueOf(st.nextToken()).intValue();
g.drawLine(x,y,x,y);
bresenham(500,60,500,360);
bresenham(501,60,501,360);
bresenham(502,60,502,360);
bresenham(503,60,503,360);
bresenham(504,60,504,360);
while(line.size()>0)
{ pixel = (String)line.remove(0);
st = new StringTokenizer(pixel);
x = Integer.valueOf(st.nextToken()).intValue();
y = Integer.valueOf(st.nextToken()).intValue();
g.drawLine(x,y,x,y);
bresenham(0,361,615,361);//used to get a pixel according to algo.. . func not provided
bresenham(0,362,615,362);
bresenham(0,363,615,363);
bresenham(0,364,615,364);
bresenham(0,365,615,365);
while(line.size()>0)
{ pixel = (String)line.remove(0);
st = new StringTokenizer(pixel);
x = Integer.valueOf(st.nextToken()).intValue();
y = Integer.valueOf(st.nextToken()).intValue();
g.drawLine(x,y,x,y);
if(initial==true)
g.setColor(Color.RED);
for(int i = no_ring;i>0;i--)
{ g.drawLine(100-(i*8),360-(no_ring - i)*10,100+(i*8)+5,360-(no_ring - i)*10);
g.drawLine(100-(i*8),359-(no_ring - i)*10,100+(i*8)+5,359-(no_ring - i)*10);
g.drawLine(100-(i*8),358-(no_ring - i)*10,100+(i*8)+5,358-(no_ring - i)*10);
g.drawLine(100-(i*8),357-(no_ring - i)*10,100+(i*8)+5,357-(no_ring - i)*10);
g.drawLine(100-(i*8),356-(no_ring - i)*10,100+(i*8)+5,356-(no_ring - i)*10);
// draw for each rod
//System.out.println("rod11:"+rod11);
//System.out.println("rod22:"+rod22);
//System.out.println("rod33:"+rod33);
int r1 = rod11.size();
int r2 = rod22.size();
int r3 = rod33.size();
String rd1,rd2,rd3;
int r11,r12,r21,r22,r31,r32;
if(initial == false)
{ g.setColor(Color.RED);
while(rod11.size()>0)
{ r12 = rod11.size()-1;
rd1 = (String)rod11.remove(r12);
r11 = Integer.valueOf(rd1).intValue();
g.drawLine(100-((r11+1)*8),360-(r1 - (r11+1))*10,100+((r11+1)*8)+5,360-(r1 - (r11+1))*10);
g.drawLine(100-((r11+1)*8),359-(r1 - (r11+1))*10,100+((r11+1)*8)+5,359-(r1 - (r11+1))*10);
g.drawLine(100-((r11+1)*8),358-(r1 - (r11+1))*10,100+((r11+1)*8)+5,358-(r1 - (r11+1))*10);
g.drawLine(100-((r11+1)*8),357-(r1 - (r11+1))*10,100+((r11+1)*8)+5,357-(r1 - (r11+1))*10);
g.drawLine(100-((r11+1)*8),356-(r1 - (r11+1))*10,100+((r11+1)*8)+5,356-(r1 - (r11+1))*10);
while(rod22.size()>0)
{ g.setColor(Color.RED);
r22 = rod22.size()-1;
System.out.println("TEST *************************:"+r22);
try
// e.printStackTrace();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr) ;
br.readLine() ;
}catch(Exception f) {}
rd2 = ((String)rod22.remove(r22)).trim();
r21 = Integer.valueOf(rd2).intValue();
g.drawLine(300-((r22+1)*8),360-(r2 - (r22+1))*10,300+((r22+1)*8)+5,360-(r2 - (r22+1))*10);
g.drawLine(300-((r22+1)*8),359-(r2 - (r22+1))*10,300+((r22+1)*8)+5,359-(r2 - (r22+1))*10);
g.drawLine(300-((r22+1)*8),358-(r2 - (r22+1))*10,300+((r22+1)*8)+5,358-(r2 - (r22+1))*10);
g.drawLine(300-((r22+1)*8),357-(r2 - (r22+1))*10,300+((r22+1)*8)+5,357-(r2 - (r22+1))*10);
g.drawLine(300-((r22+1)*8),356-(r2 - (r22+1))*10,300+((r22+1)*8)+5,356-(r2 - (r22+1))*10);
while(rod33.size()>0)
{ g.setColor(Color.RED);
r32 = rod33.size()-1;
rd3 = (String)rod33.remove(r32);
r31 = Integer.valueOf(rd3).intValue();
g.drawLine(500-((r32+1)*8),360-(r3 - (r32+1))*10,500+((r32+1)*8)+5,360-(r3 - (r32+1))*10);
g.drawLine(500-((r32+1)*8),359-(r3 - (r32+1))*10,500+((r32+1)*8)+5,359-(r3 - (r32+1))*10);
g.drawLine(500-((r32+1)*8),358-(r3 - (r32+1))*10,500+((r32+1)*8)+5,358-(r3 - (r32+1))*10);
g.drawLine(500-((r32+1)*8),357-(r3 - (r32+1))*10,500+((r32+1)*8)+5,357-(r3 - (r32+1))*10);
g.drawLine(500-((r32+1)*8),356-(r3 - (r32+1))*10,500+((r32+1)*8)+5,356-(r3 - (r32+1))*10);
why i m not able to use repaint() method in tower class? from where i can use repaint() methodi can't read your code - not formatted with code tags
I have no chance of getting it to compile (AboutDialog class?? p.draw() ??)
here's a basic routine - add a couple of things to this to demonstrate what is not
being redrawn
(compare the readability of below code (using tags) to yours)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame
public Testing()
setSize(400,300);
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
final DrawPanel dp = new DrawPanel();
JButton btn = new JButton("Change Text Location/Repaint");
getContentPane().add(dp,BorderLayout.CENTER);
getContentPane().add(btn,BorderLayout.SOUTH);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
dp.x = (int)(Math.random()*300);
dp.y = (int)(Math.random()*150)+50;
repaint();}});
public static void main(String[] args){new Testing().setVisible(true);}
class DrawPanel extends JPanel
int x = 50, y = 50;
public void paintComponent(Graphics g)
super.paintComponent(g);
g.drawString("Hello World",x,y);
} -
Using an array in another class to set text of a button
I am trying to use an array from one class in another to set the text of a button.
This is the code in the class where i have made the array.
public class EnterHomeTeam
public int NumberOfPlayers = 11;
public String[] PlayerName = new String [NumberOfPlayers];
private void button1_Click (Object sender, System.EventArgs e)
PlayerName [0] = this.HGoalKeeper.toString();
PlayerName [1] = this.HDef1.toString();
PlayerName [2] = this.HDef2.toString();
PlayerName [3] = this.HDef3.toString();
PlayerName [4] = this.HDef4.toString();
PlayerName [5] = this.HMid1.toString();
PlayerName [6] = this.HMid2.toString();
PlayerName [7] = this.HMid3.toString();
PlayerName [8] = this.HMid4.toString();
PlayerName [9] = this.HAtt1.toString();
PlayerName [10] = this.HAtt2.toString();
Players IM = new Players();
this.Hide();
IM.Show();
}Then in the class where i want to use the variables (ie. PlayerName[0]) I have got
public class Players
EnterHomeTeam HT = new EnterHomeTeam();
//and included in the button code
this.button1.set_Text(HT.PlayerName[0]);I hope i have explained this well enough and hope someone can help me solve this problem! Im not a very competent programmer so i apologise if I havent explained this well enough!
Adam.NET automatically generates quite a bit of code.... this is button1:
private void InitializeComponent()
this.button1 = new System.Windows.Forms.Button();
// button1
this.button1.set_BackColor(System.Drawing.Color.get_LightBlue());
this.button1.set_Location(new System.Drawing.Point(88, 32));
this.button1.set_Name("button1");
this.button1.set_Size(new System.Drawing.Size(72, 56));
this.button1.set_TabIndex(0);
this.button1.set_Text(HT.PlayerName[0]);
this.button1.add_Click( new System.EventHandler(this.button1_Click) );
this.get_Controls().Add(this.button1);
private void button1_Click (Object sender, System.EventArgs e)
System.out.print(HT.PlayerName[0]);
GKAction GK = new GKAction();
this.Hide();
GK.Show();
}Hope that helps - im pretty sure that's all the button1 code
Maybe you are looking for
-
Flash won't install properly and I need your help!
Details: -Computer: Mac OS X 10.5.8 (Intel Core 2 Duo) -Browser: Safari 5.0.5 (5533.21.1) -Flash version: Flash 10.3 -Problem: Installation seems successful, but websites still cannot play Flash content and request (again) I download the latest versi
-
Menu problems in IE and Chrome
Okay, the site is www.rainbowmorganhorseassoc.com. I'm having 2 different issues with 2 different browsers, only it's not me having the issues, it's others. Everything is working fine for me in the same versions of the browsers, so I'm having difficu
-
Cannot find symbol class entry
.\ListGraph.java:26: cannot find symbol symbol : class Entry location: class Map for(Map.Entry<Stad,List<ListEdge>> me : nodes.entrySet()) ^ 1 error this is what i get when i try to compile this code, its the lowest part thats getting errors: import
-
COOIS- Report Grid Value not displaying
Hi Experts, In COOIS report Prd Order item details , the grid values and stock category are not displaying values. we created the production order with AFS grid but while seeing report of item details the grid values and stock category
-
EHS Personal Data Screen is Missing
Hi, I have question regarding Occupational Health..when I go to Edit Medical Service tcode is "ehsambtaet"..Personal data screen is missing.So i am unable to see the Medical service assigned to a person. Is there is any configuration is required for