Change Class problems

hi,i have 4 files :

satu.java

import java.awt.BorderLayout;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JFrame;

publicclass satu{

/**

* @param args

*/

publicstaticvoid main(String[] args){

// TODO Auto-generated method stub

JFrame.setDefaultLookAndFeelDecorated(true);

final JFrame appp =new JFrame("TEST ");

appp.setSize(150,180);

appp.setUndecorated(true);

appp.setResizable(false);

//testmenunew m = new testmenunew();

//m.start();

//m.init();

appp.setSize(540,430);

dua m =new dua(appp);

m.init();

//TestHeaderRenderer m = new TestHeaderRenderer();

appp.add(m,BorderLayout.CENTER);

appp.setVisible(true);

//appp.setLocationRelativeTo(null);

appp.addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent evt){

appp.setVisible(false);

appp.dispose();

}

});

}

}

dua.java

import java.applet.Applet;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

publicclass duaextends Appletimplements ActionListener{

/**

* @param args

*/

JFrame myframe;

JPanel test;

public dua(JFrame sat){

myframe = sat;

}

publicvoid init(){

this.setLayout(null);

JButton x =new JButton("Big");

x.setBounds(0,0,100,20);

x.addActionListener(this);

add(x);

test =new JPanel();

test.setBounds(5,35,500,200);

test.setBackground(Color.black);

tiga s =new tiga();

s.init();

s.setSize(new Dimension(400,100));

test.add(s);

add(test);

}

publicvoid actionPerformed(ActionEvent arg0){

// TODO Auto-generated method stub

int newx = myframe.getWidth()+10;

int newy = myframe.getHeight()+10;

//myframe.removeNotify();

//myframe.setUndecorated(true);

System.out.println(myframe.isDisplayable());

myframe.setTitle("X = "+newx+" Y = "+newy);

myframe.setSize(newx,newy);

myframe.validate();

//myframe.addNotify();

}

}

tiga.java

import java.applet.Applet;

import java.awt.Color;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JLabel;

publicclass tigaextends Applet{

public tiga(){

}

publicvoid init(){

this.setLayout(null);

setBackground(Color.red);

JLabel testlab =new JLabel("Click Here");

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

publicvoid mouseClicked(MouseEvent arg0){

// TODO Auto-generated method stub

pindah();

}

publicvoid mousePressed(MouseEvent arg0){

// TODO Auto-generated method stub

}

publicvoid mouseReleased(MouseEvent arg0){

// TODO Auto-generated method stub

}

publicvoid mouseEntered(MouseEvent arg0){

// TODO Auto-generated method stub

}

publicvoid mouseExited(MouseEvent arg0){

// TODO Auto-generated method stub

}

});

add(testlab);

}

publicvoid pindah(){

empat xx=new empat();

xx.init();

add(xx);

}

}

empat.java

import java.applet.Applet;

import java.awt.Color;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.JLabel;

publicclass empatextends Applet{

public empat(){

}

publicvoid init(){

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab =new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

add(testlab);

}

}

the problem is when i run satu.java,then there is a JLabel "Click Here" inside JPanel "test",and when i click on Click Here,i want call emapt.java to be viewed at "test" JPanel,and remove "tiga.java" from "test" JPanel.

but my code doesn't work...please help me.

thanks.

[8895 byte] By [ox_ten_wingsa] at [2007-10-3 5:22:37]
# 1
nobody can help me ?
ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 2

> nobody can help me ?

1) You only posted 30 minutes ago. I personally ignore people who expect that everybody should drop what they are currently doing to answer your question.

2) You've been asked to post Swing related questions in the Swing forum before

3) You've been told not to extend Applet before. This is a Swing application not a Java Applet. You don't mix Applets and Applications and AWT components and Swing components.

So basically you don't listen to past suggestions, so why should I make more?

camickra at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 3

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.applet.*;

public class satu {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

JFrame.setDefaultLookAndFeelDecorated(true);

final JFrame appp = new JFrame("TEST ");

appp.setUndecorated(true);

appp.setResizable(false);

//testmenunew m = new testmenunew();

//m.start();

//m.init();

appp.setSize(540,430);

dua m = new dua(appp);

m.init();

//TestHeaderRenderer m = new TestHeaderRenderer();

appp.add(m,BorderLayout.CENTER);

appp.setVisible(true);

//appp.setLocationRelativeTo(null);

appp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

class dua extends Applet implements ActionListener {

/**

* @param args

*/

JFrame myframe;

JPanel test;

public dua(JFrame sat){

myframe = sat;

}

public void init(){

this.setLayout(null);

JButton x = new JButton("Big");

x.setBounds(0,0,100,20);

x.addActionListener(this);

add(x);

test = new JPanel();

test.setBounds(5,35,500,200);

test.setBackground(Color.black);

tiga s = new tiga();

s.init();

s.setSize(new Dimension(400,100));

test.add(s);

add(test);

}

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

int newx = myframe.getWidth()+10;

int newy = myframe.getHeight()+10;

System.out.println(myframe.isDisplayable());

myframe.setTitle("X = "+newx+" Y = "+newy);

myframe.setSize(newx,newy);

myframe.validate();

}

}

class tiga extends Applet implements MouseListener{

public tiga(){

}

public void init(){

this.setLayout(null);

setBackground(Color.red);

JLabel testlab = new JLabel("Click Here");

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(this);

add(testlab);

}

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void pindah(){

empat xx= new empat();

xx.init();

xx.setBounds(20,20,200,50);

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

}

}

class empat extends Applet {

public empat(){

}

public void init(){

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

add(testlab);

}

}

pravintha at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 4

thanks pravinth..

now i got another problems..

i try ti change dua.java to :

import java.applet.Applet;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class dua extends Applet implements ActionListener {

/**

* @param args

*/

JFrame myframe;

JPanel test;

JPanel contentPane;

public dua(JFrame sat){

myframe = sat;

}

public void init(){

Font f = new Font("Arial",Font.BOLD,10);

/*this.setLayout(null);

JButton x = new JButton("Big");

x.setBounds(0,0,100,20);

x.addActionListener(this);

add(x);

test = new JPanel();

test.setBounds(5,35,500,200);

test.setBackground(Color.black);

tiga s = new tiga(test);

s.init();

s.setSize(new Dimension(400,100));

test.add(s);

add(test);

JLabel ex = new JLabel("xxxxxxx");

ex.setBounds(110,0,100,20);

add(ex);*/

this.setLayout(null);

setBackground(new Color(0,0,130));

final JLabel keluar = new JLabel("Logout", JLabel.CENTER);

final JLabel pilih = new JLabel("Choose Room", JLabel.CENTER);

keluar.setBorder(BorderFactory.createLineBorder(new Color(215,215,215)));

keluar.setBounds(80,20,80,15);

keluar.setForeground(Color.white);

keluar.setFont(f);

keluar.setVisible(false);

keluar.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

pilih.setVisible(true);

keluar.setVisible(true);

}

public void mouseExited(MouseEvent e) {

pilih.setVisible(false);

keluar.setVisible(false);

}

});

add(keluar);

pilih.setBorder(BorderFactory.createLineBorder(new Color(215,215,215)));

pilih.setBounds(0,20,80,15);

pilih.setForeground(Color.white);

pilih.setFont(f);

pilih.setVisible(false);

pilih.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {

pilihruang();

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

pilih.setVisible(true);

keluar.setVisible(true);

}

public void mouseExited(MouseEvent e) {

pilih.setVisible(false);

keluar.setVisible(false);

}

});

add(pilih);

JLabel start = new JLabel("Start", JLabel.CENTER);

start.setBorder(BorderFactory.createLineBorder(Color.white));

start.setBounds(0,5,80,15);

start.setForeground(Color.white);

start.setFont(f);

start.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {

}

public void mouseReleased(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

pilih.setVisible(true);

keluar.setVisible(true);

}

public void mouseExited(MouseEvent e) {

pilih.setVisible(false);

keluar.setVisible(false);

}

});

add(start);

contentPane = new JPanel();

contentPane.setBackground(Color.black);

contentPane.setBounds(0,40,530,380);

add(contentPane);

}

public void actionPerformed(ActionEvent arg0) {

// TODO Auto-generated method stub

int newx = myframe.getWidth()+10;

int newy = myframe.getHeight()+10;

//myframe.removeNotify();

//myframe.setUndecorated(true);

System.out.println(myframe.isDisplayable());

myframe.setTitle("X = "+newx+" Y = "+newy);

myframe.setSize(newx,newy);

myframe.validate();

//myframe.addNotify();

}

public void pilihruang(){

contentPane.setVisible(false);

remove(contentPane);

contentPane = new JPanel();

contentPane.setBackground(Color.black);

contentPane.setBounds(0,40,530,380);

tiga m = new tiga();

m.init();

m.setSize(new Dimension(520,370));

contentPane.add(m);

add(contentPane);

}

}

then when i click "Click here",rmpat.java is appeared,but when i move my mouse above START,the four.java changed to center..why it's happened ?thanks..

ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 5

public void pindah(){

empat xx= new empat();

xx.init();

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

}

Note:this change in component-positions or size is only due to the layoutManagers,or if u r using null-layoutmanager-no layout manager-then it depends upon the setBounds(...)method you are using. you check your code deeply you can easily figure it out.If a components position is changing automatically-then there must be some code in somewhere which can do it-or there must be some layoutmanagers.

want more?

pravintha at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 6
yep...but now i change the empat.java,i add some button,some label and JPanel,n now i cannot view the button and the label,but i can view the Jpanel..what's wrong with that ?thanks.
ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 7
o'y,almost forgot....when i move the mouse to "Start" menu,the button and the label is appeared...
ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 8

>>now i change the empat.java

Then how can i know the problem-if its in the empat.java(you haven't posted the updated codeeeeeeeeeeeeeee)

>> add some button,some label and JPanel,n now i cannot view the button and the label,but i can view the Jpanel..what's wrong with that ?

if you really want to know the problem .please post the complete runnable updated code. I am leaving now.may return back after some 3hours.You better post here everyting.

pravintha at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 9
ok...i got it now....pravinth,thanks for ur help....
ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 10
U are the most welcome one boy. Take Care Bye!
pravintha at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 11

hi,im back today......

i got another problems,i want to add keylistener to empat.java,but it doesn't work....this is my code :

import java.applet.Applet;

import java.awt.Button;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Event;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import javax.swing.JLabel;

public class empat extends Applet implements KeyListener {

public empat(){

}

public void init(){

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

Button gol = new Button("Test");

gol.setBounds(20,60,100,20);

add(gol);

add(testlab);

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

}

/*public boolean action(Event e,Object o){

repaint();

return true;

}*/

/*public void paint(Graphics g){

Random z= new Random();

int x = z.nextInt(100);

int y = z.nextInt(100);

g.drawLine(0,0,x,y);

}*/

public void pindah(){

empat xx= new empat();

xx.init();

xx.setSize(new Dimension(400,200));

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

repaint();

}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyPressed(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyReleased(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

}

thanks.

ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 12
And where are you adding the KeyListener to anything? Implementing it is one thing but you also have to add it to something.
cotton.ma at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 13
i want to add it to empat.java,i meant when i can press key anywhere inside the empat.java...
ox_ten_wingsa at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 14
And what do you want to happen once you get this to work? What is your key listener actually going to be doing?
cotton.ma at 2007-7-14 23:29:40 > top of Java-index,Java Essentials,Java Programming...
# 15
> i want to add it to empat.java,i meant when i can> press key anywhere inside the empat.java...Add the following line to your init method.addKeyListener(this);
cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 16

i have another function in that keylsitener....

import java.applet.Applet;

import java.awt.Button;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Event;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class empat extends Applet implements KeyListener {

public empat(){

}

public void init(){

this.addKeyListener(this); //-> i try to add this,but it still doesn't work.

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

Button gol = new Button("Test");

gol.setBounds(20,60,100,20);

add(gol);

add(testlab);

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

//setEnabled(false);

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

}

/*public boolean action(Event e,Object o){

repaint();

return true;

}*/

/*public void paint(Graphics g){

Random z= new Random();

int x = z.nextInt(100);

int y = z.nextInt(100);

g.drawLine(0,0,x,y);

}*/

public void pindah(){

empat xx= new empat();

xx.init();

xx.setSize(new Dimension(400,200));

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

repaint();

}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyPressed(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");//--> i will add the function here

}

public void keyReleased(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

}

ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 17

i meant like this :

import java.applet.Applet;

import java.awt.Button;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Event;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class empat extends Applet implements KeyListener {

int x = 0;

public empat(){

}

public void init(){

addKeyListener(this);

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

Button gol = new Button("Test");

gol.setBounds(20,60,100,20);

add(gol);

add(testlab);

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

//setEnabled(false);

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

}

/*public boolean action(Event e,Object o){

repaint();

return true;

}*/

/*public void paint(Graphics g){

Random z= new Random();

int x = z.nextInt(100);

int y = z.nextInt(100);

g.drawLine(0,0,x,y);

}*/

public void pindah(){

empat xx= new empat();

xx.init();

xx.setSize(new Dimension(400,200));

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

repaint();

}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyPressed(KeyEvent arg0) {

// TODO Auto-generated method stub

presstime();

System.out.println("X = "+x);

}

public void keyReleased(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void presstime(){

x++;

}

}

but it still doesn't work.

Message was edited by:

ox_ten_wings

ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 18
hello,mr cotton..are u still there ?
ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 19
> hello,mr cotton..are u still there ?Patience please young grasshopper. I have to turn your code into something I can actually test with.Add the following line (KEEP THE addKeyListener LINE!)this.setFocusable(true);
cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 20
> Patience please young grasshopper. He doesn't have patience. Didn't you see my first reply.
camickra at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 21

yep.it still can't work :

import java.applet.Applet;

import java.awt.Button;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Event;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class empat extends Applet implements KeyListener {

int x = 0;

public empat(){

}

public void init(){

addKeyListener(this);

this.setFocusable(true);

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

Button gol = new Button("Test");

gol.setBounds(20,60,100,20);

add(gol);

add(testlab);

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

//setEnabled(false);

//getParent().setEnabled(false);

//pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

//setEnabled(false);

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

}

/*public boolean action(Event e,Object o){

repaint();

return true;

}*/

/*public void paint(Graphics g){

Random z= new Random();

int x = z.nextInt(100);

int y = z.nextInt(100);

g.drawLine(0,0,x,y);

}*/

public void pindah(){

empat xx= new empat();

xx.init();

xx.setSize(new Dimension(400,200));

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

repaint();

}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyPressed(KeyEvent arg0) {

// TODO Auto-generated method stub

presstime();

System.out.println("X = "+x);

}

public void keyReleased(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void presstime(){

x++;

}

}

em,before i run empat.java, i start it at satu.java.

u can see satu.java,dua.java,tiga.java at the beginning of this topic.

Message was edited by:

ox_ten_wings

ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 22

> > Patience please young grasshopper.

>

> He doesn't have patience. Didn't you see my first

> reply.

Yes. I am well acquainted with ox_ten

http://forum.java.sun.com/thread.jspa?threadID=770125&start=1

I don't know why entirely I am helping. Just in the mood I suppose. I don't expect it will actually go anywhere.

cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 23
mr.cotton..it still cannot work.
ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 24

> mr.cotton..it still cannot work.

oxten,

That satu stuff is... something. This is a hopeless mess I'm afraid to tell you. I saw camickr mention something about not using applets and I was pained to see the Applet here but thought I'd just try and carry on.

So now I fully understand that you intend to add Applets willy nilly to your application.

Yikes!

Here for the love of god use this version of empat instead

import java.awt.Button;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Event;

import java.awt.Graphics;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.util.Random;

import java.awt.Frame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class empat extends Frame implements KeyListener {

public empat(){

this.addKeyListener(this); //-> i try to add this,but it still doesn't work.

this.setFocusable(true);

this.setLayout(null);

setBackground(Color.YELLOW);

JLabel testlab = new JLabel("This is 4our");

testlab.setBounds(10,0,200,50);

Button gol = new Button("Test");

gol.setBounds(20,60,100,20);

add(gol);

add(testlab);

testlab.setBounds(10,0,200,50);

testlab.addMouseListener(new MouseListener(){

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

pindah();

}

public void mousePressed(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

//setEnabled(false);

}

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

});

setSize(400,400);

show();

}

/*public boolean action(Event e,Object o){

repaint();

return true;

}*/

/*public void paint(Graphics g){

Random z= new Random();

int x = z.nextInt(100);

int y = z.nextInt(100);

g.drawLine(0,0,x,y);

}*/

public void pindah(){

/*empat xx= new empat();

xx.init();

xx.setSize(new Dimension(400,200));

xx.setBounds(getParent().getComponent(0).getBounds());

getParent().add(xx);

getParent().remove(getParent().getComponent(0));

repaint();*/

}

public void keyTyped(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public void keyPressed(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");//--> i will add the function here

}

public void keyReleased(KeyEvent arg0) {

// TODO Auto-generated method stub

System.out.println("aaaa");

}

public static void main(String args[]){

empat emp = new empat();

}

}

cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 25
so ?i cannot extends Applet ?hem....is there another way by extending applet ?
ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 26
> so ?i cannot extends Applet ?For you no. There is no way. Do not extend Applet. Do not pass go. Do not collect $200.If you want to extend something besides Frame extend Panel.
cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 27
so,anyone can help me by extend applets ?
ox_ten_wingsa at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 28
> so,anyone can help me by extend applets ?NONonoNOnoNONON
cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 29
> so,anyone can help me by extend applets ?And stop asking. You have no good reason to do this. It's stupid and it's wrong.STOP ASKING! ACTUALLY LISTEN TO SOME ADVICE.Thank you. Have a lovely day.
cotton.ma at 2007-7-21 11:01:28 > top of Java-index,Java Essentials,Java Programming...
# 30
> so,anyone can help me by extend applets ?Why do you keep trying to do this when you've been told it's the wrong approach and will not work? What is it with your love of applets?
jverda at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 31
ox is either a very bored troll, or the stubbornest person since daFei.
jverda at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 32
i want to di this,coz all my application file using extends Applet..so ?
ox_ten_wingsa at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 33

> i want to di this,

No

> coz all my application file using

> extends Applet..so ?

NOOOOOOOOOOOOOOOOOOOOOOOOO

No No No No

No No No

No

I think pravinth phrased it beautifully in your basically same thread yesterday when he said

"I am wondering y do you want to use only that oooooolllddd Applet

[(u got a message from Mr.old Applet>>hi boy i am really old and my young fellows are doing more work than me,still y do u want to use me.....cough, cough)]"

cotton.ma at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 34

> i want to di this,coz all my application file using

> extends Applet..so ?

So, as you've already been told, MANY times: IT WON'T FREAKIN' WORK! FORGET BLODDY APPLETS HERE!

Do you want to actually learn anything? Or do you think that if you keep asking the same question over and over, eventually the answer you want to hear will magically become correct?

jverda at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 35
> ox is either a very bored troll, or the stubbornest> person since daFei.Yes. :|
cotton.ma at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 36

> i want to di this,coz all my application file using

> extends Applet..so ?

" ___ _ ___"

" | \ | |/ \_ ___ __| || |_/ _|_ __ "

" | \| | / _ \/ _ \| '_ \ | '_ \ | | / _ \ | __|| |_/ _ \ | '__|"

" | |\ | | (_) |/ \ | |_) | | |_) | | | | __/ | |_| _| | (_) | | |"

" |_| \_| \//_/\_\ | .__/ | .__/ |_| \| \__||_|\/ |_|"

"|_||_|"

" _ "

" ____ | |"

" | | | | / _ \ | | | | | |"

" | |_| | | (_) | | |_| | |_|"

" \__, | \/\__,_| (_)"

" |/ "

cotton.ma at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 37
You bastards! Why won't you let him join the club and tell him the uber secrets of Applets?
floundera at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 38
shh flounder shh. we almost have him convinced that applets aren't useful. if he discovers the power of applets we may all lose our jobs.
prob.not.sola at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 39
secrets of Applets ?
ox_ten_wingsa at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 40
please tell me a little,just to solve my problems...please...
ox_ten_wingsa at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 41
> please tell me a little,just to solve my> problems...please...sorry we can't.it's better for everyone if you use JFrames and Panels. please. you don't want me to get fired, do you?
prob.not.sola at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 42
no,i dont want u to get fired.but can u give me just a little help,please....all of my files using extends Applet,so...........................hem....
ox_ten_wingsa at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 43

> no,i dont want u to get fired.but can u give me just

> a little help,please....

> all of my files using extends

> Applet,so...........................hem....

the only option is to use Swing and JFrames instead. it will be better for my family, and i think it will be useful for you to. i appreciate your help in this matter.

prob.not.sola at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 44

> > it's better for everyone if you use JFrames and Panels

Actually, thats JPanel.

> please tell me a little,just to solve my problems...please...

I've told you twice before. Three strikes and your out.

The whole point of this thread is that you don't extend Applet. You would extend JPanel and add your components to the panel.

It probably won't solve your problem, because yes Applet does extend Container, so theoretically you should be able to add Swing components to it. But Applet is an AWT component and the first rule when creating a Swing application is to not mix AWT components with Swing components.

That fact that you are trying to extend Applet and add it to a JFrame makes it look like you don't know what your are doing.

A JFrame indicates you want to create an Application which means its a program that runs on your computer.

An Applet is a program that runs in a web browser.

Mixing the two is confusing, even if it might technically work.

camickra at 2007-7-21 11:01:33 > top of Java-index,Java Essentials,Java Programming...
# 45
> all of my files using extends Applet,so...........................hem.... So change it to extend JPanel.Then you also need to get rid of the init() method and move all that code to the constructor of your class.Better to do it now rather than later.
camickra at 2007-7-21 11:01:38 > top of Java-index,Java Essentials,Java Programming...
# 46
> That fact that you are trying to extend Applet and> add it to a JFrame makes it look like you don't know> what your are doing.Understatement of the year.
floundera at 2007-7-21 11:01:38 > top of Java-index,Java Essentials,Java Programming...
# 47
huaaaaaaaahhhhhhhh...finally i got it........thankss...
ox_ten_wingsa at 2007-7-21 11:01:38 > top of Java-index,Java Essentials,Java Programming...
# 48
We should be happy that noone has yet pointed out the secrets of J5EE and told him that if he stop extending everyting with Applet and start using Servlet insted, he will get a much more powerfull application.Applet is nothing compated to Servlet...
Lajma at 2007-7-21 11:01:38 > top of Java-index,Java Essentials,Java Programming...