我剛剛安裝了Netbeans IDE 7.0,並試圖基於圖像處理運行我的項目(該命令在傳統方法中使用命令提示符運行時運行正常),但小程序查看器顯示爲start: applet not initialized
,而編譯(build
Netbeans任務)成功。從命令提示符切換到網豆
這裏我附加了2個相關的Java文件,而整個項目還有3-4個用於圖像渲染的java文件。
/*
* <applet code=ImageFilterDemo width=350 height=450>
* <param name=img value=strawberry.jpeg>
* <param name=filters value="Grayscale+Invert+Contrast+Blur+Sharpen">
* </applet>
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.awt.image.* ;
public class ImageFilterDemo extends Applet implements ActionListener {
Image img;
PlugInFilter pif;
Image fimg;
Image curImg;
LoadedImage lim;
Label lab;
Button reset;
Button histograph;
Dimension d;
static int iw, ih;
int pixels[];
static int w, h,just;
static int hist[] = new int[256];
static int max_hist = 0;
public void init() {
setLayout(new BorderLayout());
Panel p = new Panel();
add(p, BorderLayout.SOUTH);
reset = new Button("Reset");
histograph = new Button("Histograph");
reset.addActionListener(this);
histograph.addActionListener(this);
p.add(reset);
p.add(histograph);
StringTokenizer st = new StringTokenizer(getParameter("filters"), "+");
while(st.hasMoreTokens()) {
Button b = new Button(st.nextToken());
b.addActionListener(this);
p.add(b);
}
lab = new Label("");
add(lab, BorderLayout.NORTH);
img = getImage(getDocumentBase(),"strawberry.jpeg");
lim = new LoadedImage(img);
add(lim, BorderLayout.CENTER);
d = getSize();
w = d.width;
h = d.height;
try {
//img = getImage(getDocumentBase(), getParameter("img"));
MediaTracker t = new MediaTracker(this);
t.addImage(img, 0);
t.waitForID(0);
iw = img.getWidth(null);
ih = img.getHeight(null);
pixels = new int[iw * ih];
PixelGrabber pg = new PixelGrabber(img, 0, 0, iw, ih,
pixels, 0, iw);
pg.grabPixels();
} catch (InterruptedException e) { };
for (int i=0; i<iw*ih; i++) {
int pii = pixels[i];
int r = 0xff & (pii >> 16);
int g = 0xff & (pii >> 8);
int b = 0xff & (pii);
int y = (int) (.33 * r + .56 * g + .11 * b);
hist[y]++;
}
for (int i=0; i<256; i++) {
if (hist[i] > max_hist)
max_hist = hist[i];
}
}
public void actionPerformed(ActionEvent ae) {
String a = "";
try {
a = (String)ae.getActionCommand();
if (a.equals("Reset")) {
lim.set(img);
lab.setText("Normal");
}
else if(a.equals("Histograph")){
lab.setText("Histo_graph");
just=1;
lim.repaint();
}
else {
pif = (PlugInFilter) Class.forName(a).newInstance();
fimg = pif.filter(this, img);
lim.set(fimg);
lab.setText("Filtered: " + a);
}
repaint();
} catch (ClassNotFoundException e) {
lab.setText(a + " not found");
lim.set(img);
repaint();
} catch (InstantiationException e) {
lab.setText("could't new " + a);
} catch (IllegalAccessException e) {
lab.setText("no access: " + a);
}
}
}
// 2nd file
import java.awt.*;
public class LoadedImage extends Canvas {
Image img;
public LoadedImage(Image i) {
set(i);
}
void set(Image i) {
MediaTracker mt = new MediaTracker(this);
mt.addImage(i, 0);
try {
mt.waitForAll();
} catch (InterruptedException e) { };
img = i;
repaint();
}
public void paint(Graphics g) {
if (img == null) {
g.drawString("no image", 10, 30);
}
else if(ImageFilterDemo.just==1){
int x = (ImageFilterDemo.w - 256)/2;
int lasty = ImageFilterDemo.h - ImageFilterDemo.h * ImageFilterDemo.hist[0]/ImageFilterDemo.max_hist;
for (int i=0; i<256; i++, x++) {
int y = ImageFilterDemo.h - ImageFilterDemo.h * ImageFilterDemo.hist[i]/ImageFilterDemo.max_hist;
g.setColor(new Color(i, i, i));
g.fillRect(x, y, 1, ImageFilterDemo.h);
g.setColor(Color.red);
g.drawLine(x-1,lasty,x,y);
lasty = y;
}
ImageFilterDemo.just=0;
}
else {
g.drawImage(img, 0, 0, this);
}
}
public Dimension getPreferredSize() {
return new Dimension(img.getWidth(this), img.getHeight(this));
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
有我們在設置或當我們從傳統的命令提示符下運行更改編碼做任何變化,Netbeans的?
是否有任何變化,我們哈當我們從傳統的命令提示符運行到net beans時,我們可以進行設置或編碼...... –
當您在netbeans中運行它時,控制檯中是否有任何輸出? –
順便說一下,這不是一個論壇 - 它是一個(社區可編輯的)問答網站。這可能看起來像是一個迂腐的區分,但這確實意味着更多地關注提供經典正確答案的討論。特別是,您不應該發佈更多問題或「答案」來回應他人,而是編輯您的原始問題以反映更新。 –