My problem is that :After using the program once how could i re-use it again? For axample :After i push "datalar"(meaning datas) and put the datas in after that you have to push "z"(meaning draw) it starts working but after its finished you can't re-draw it again .What can i do?? :sad:
(oh and "TAMAM" means ok)
--------------

import java.awt.*;
import java.awt.event.*;

public class graf{
	public static void main(String args[]){
		Pencere pen=new Pencere();
		pen.setVisible(true);
		}
	} 
class Pencere extends Frame implements Runnable{
	Button bt_data,bt_ciz;
	int vred,vcyan,vgreen,vmagenta,vblue;
	datalar pen_data;
	boolean ciz_mi;
	Thread th_ciz;
	
	public Pencere(){
		setTitle("Ornek");
		setSize(700,400);
		setLocation(200,0);
		th_ciz=new Thread(this);
		
		
		pen_data =new datalar(this);
		
		bt_ciz=new Button("amp;#304;Z");
		bt_ciz.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae){
				th_ciz.start();
				}
			});
		bt_data=new Button("DATA");
		bt_data.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae){
				pen_data.setVisible(true);	
				}
			});
		this.setLayout(new FlowLayout());
		this.add(bt_data);this.add(bt_ciz);
			
		}
		public void paint(Graphics g){
			g.clearRect(0,0,this.getWidth(),this.getHeight());
			float toplam=Float.parseFloat(vred+vcyan+vgreen+vmagenta+vblue+".0");
			int ang_red=(int)((vred/toplam)*360);
			int ang_cyan=(int)((vcyan/toplam)*360);
			int ang_green=(int)((vgreen/toplam)*360);
			int ang_magenta=(int)((vmagenta/toplam)*360);
			int ang_blue=(int)((vblue/toplam)*360);
			int aci_toplam=ang_red+ang_cyan+ang_green+ang_magenta+ang_blue;
			if(ciz_mi)ang_blue+=Math.abs(aci_toplam-360);
			
			int bar_red=(int)((vred/toplam)*300);
			int bar_cyan=(int)((vcyan/toplam)*300);
			int bar_green=(int)((vgreen/toplam)*300);
			int bar_magenta=(int)((vmagenta/toplam)*300);
			int bar_blue=(int)((vblue/toplam)*300);
			
			try{
			g.setColor(Color.red);
			for (int i = 0; i<=ang_red; i++) {
				g.fillArc(50,50,200,200,0,i);
				th_ciz.sleep(20);
		    }
			for (int i = 0; i<=bar_red; i++) {
				g.fillRect(300,300-bar_red,30,i);
				th_ciz.sleep(20);
		    }
		    g.setColor(Color.cyan);
			for (int i = 0; i<=ang_cyan; i++) {
				g.fillArc(50,50,200,200,ang_red,i);
				th_ciz.sleep(20);
		    }
		    for (int i = 0; i<=bar_cyan; i++) {
				g.fillRect(340,300-bar_cyan,30,i);
				th_ciz.sleep(20);
		    }
		    g.setColor(Color.green);
		    ang_red+=ang_cyan;
		    for (int i = 0; i<=ang_green; i++) {
				g.fillArc(50,50,200,200,ang_red,i);
				th_ciz.sleep(20);
		    }
		    for (int i = 0; i<=bar_green; i++) {
				g.fillRect(380,300-bar_green,30,i);
				th_ciz.sleep(20);
		    }
		    ang_red+=ang_green;
		    g.setColor(Color.magenta);
		    for (int i = 0; i<=ang_magenta; i++) {
				g.fillArc(50,50,200,200,ang_red,i);
				th_ciz.sleep(20);
		    }
		    for (int i = 0; i<=bar_magenta; i++) {
				g.fillRect(420,300-bar_magenta,30,i);
				th_ciz.sleep(20);
		    }
		    ang_red+=ang_magenta;
		    g.setColor(Color.blue);
		    for (int i = 0; i<=ang_blue; i++) {
				g.fillArc(50,50,200,200,ang_red,i);
				th_ciz.sleep(20);
		    }
		    for (int i = 0; i<=bar_blue; i++) {
				g.fillRect(460,300-bar_blue,30,i);
				th_ciz.sleep(20);
		    }
		    th_ciz.stop();
			}	
			catch(Exception e){
				System.out.println (e);
				}
			
			}
		public void run(){
			repaint();
			}
		
	}
class datalar extends Frame{
	Label lb_red,lb_cyan,lb_green,lb_magenta,lb_blue;
	TextField tf_red,tf_cyan,tf_green,tf_magenta,tf_blue;
	Button bt_ok;
	Pencere ana_pen;
	
	public datalar(Pencere vana_pen){
		super("datalar");
		this.ana_pen=vana_pen;	
		lb_red=new Label("red");
		lb_cyan=new Label("cyan");
		lb_green=new Label("green");
		lb_magenta=new Label("magenta");
		lb_blue=new Label("blue");
		tf_red=new TextField(8);
		tf_cyan=new TextField(8);
		tf_green=new TextField(8);
		tf_magenta=new TextField(8);
		tf_blue=new TextField(8);
		bt_ok=new Button("TAMAM");
		
		this.setLayout(new GridLayout(6,2));
		add(lb_red);add(tf_red);
		add(lb_cyan);add(tf_cyan);
		add(lb_green);add(tf_green);
		add(lb_magenta);add(tf_magenta);
		add(lb_blue);add(tf_blue);
		add(bt_ok);
		
		bt_ok.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent ae){
				ana_pen.vred=Integer.parseInt(tf_red.getText());
				ana_pen.vcyan=Integer.parseInt(tf_cyan.getText());
				ana_pen.vgreen=Integer.parseInt(tf_green.getText());
				ana_pen.vmagenta=Integer.parseInt(tf_magenta.getText());
				ana_pen.vblue=Integer.parseInt(tf_blue.getText());
				ana_pen.ciz_mi=true;
				setVisible(false);
				}
			});
		
		this.pack();
		}
	
	}
...
Thread th_ciz;
...	
th_ciz=new Thread(this);
...
bt_ciz.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent ae){
		th_ciz.start();
	}
});

Try this:

Remove the declaration and definition of th_ciz (first two lines quoted above). Roll it all into the ActionListener:

bt_ciz.addActionListener(new ActionListener(){
	public void actionPerformed(ActionEvent ae){
		(new Thread(this)).start();
	}

Hm, that should work. If the anonymous thread isn't quite right, you can always stash it in a local Thread variable instead.

I think that's what you're asking about... So if all you're doing in the Run method is calling repaint(), is there a good reason you can't do that from the button's handler?

This article has been dead for over six months. Start a new discussion instead.