开发者

Want to use one int array in Main Function from thread's run() function

开发者 https://www.devze.com 2023-01-26 20:30 出处:网络
public class fraktal extends JFrame{ public fr开发者_如何学编程aktal (String args[]) { calc = new Calculator(632,453,raster, this);
public class fraktal extends JFrame   {

 public fr开发者_如何学编程aktal (String args[]) {
  calc = new Calculator(632,453,raster, this);    
  }
 calc.start();


 } 
 public static void main(String args[]) {
  new fraktal(args);
 }

}

class Calculator extends Thread {
 public Calculator(int sx, int sy, WritableRaster r, JFrame p) {

 public void run() {  
  int[] dataArray = new int[3600000];
  raster.getPixels(0,0,32,53,dataArray);  
  //System.out.println(Arrays.toString(dataArray));    
 } 
}

I wanna use "dataArray" , a int array in Main, how Can I get it? Thanks indeed!


Here in your code there are many mistakes, if you just want to use dataArray in Main method here is snippet. try correcting mistakes and also check the link given

import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.image.WritableRaster;


public class fraktal extends JFrame   {
 int[] dataArray;
 public fraktal (String args[]) {
  Calculator calc = new Calculator(dataArray);    
  calc.start();
  }




 public static void main(String args[]) {
 fraktal ob =  new fraktal(args);
 System.out.println(ob.dataArray);
 }

}

class Calculator extends Thread {
 int[] dataArray;

 public Calculator(int[] dataArray) {
   this.dataArray = dataArray;
 }
 public void run() {    
  System.out.println(Arrays.toString(dataArray));    
 } 
}   

Java Variable Scope Documentation


You can easily add getters to Calculator and fraktal. Smt like getMyArray().

0

精彩评论

暂无评论...
验证码 换一张
取 消