public class RecBt extends Frame { DPanel pan = new DPanel(); int bars = 3;
public RecBt(int w, int h) { super(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { dispose(); System.exit(0); } public void windowDeiconified(WindowEvent ev) { bars = 4; } }); setBounds(6,6,w,h); add(pan); setVisible(true); } public class DPanel extends Panel { Image image; Color color[] = new Color[4];
public DPanel() { image = getToolkit().createImage("flower.jpeg"); MediaTracker tracker = new MediaTracker(this); tracker.addImage(image,0); try { tracker.waitForID(0); } catch (InterruptedException e){} color[0] = Color.red; color[1] = Color.blue; color[2] = Color.gray; color[3] = Color.orange; } public void paint(Graphics g) { super.paint(g); int h2 = getHeight()/2; for (int j=0; j < bars; j++) { Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars); g.setColor(color[j]); bar.draw(g); } g.drawImage(image,0,h2,getWidth(),h2,null); } } public class Bar { int x,y,width,height,num; String text;
public Bar(int num, int x, int y, int w, int h) { this.num = num; this.x = x; this.y = y; width = w; height = h; if (num == 3) text = num+" This Is The Extra Line "+num; else text = num+"Agkgkgkgkgkgkgkgkgkgkgkgk"+num; } public void draw(Graphics g) { g.fillRect(x,y,width,height); g.setColor(Color.white); g.setFont(new Font("",0,height/2)); FontMetrics fm = getFontMetrics(g.getFont()); int tw = fm.stringWidth(text); g.drawString(text,(width-tw)/2,y+height/2); } } public static void main (String[] args) { new RecBt(500,350); } }
errors
C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:34: Incompatible type for method. Can't convert java.lang.String to byte[]. image = getToolkit().createImage("flower.jpeg"); ^ C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:50: Method getHeight() not found in inner class RecBt. DPanel. int h2 = getHeight()/2; ^ C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:53: Method getWidth() not found in inner class RecBt. DPanel. Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars); ^ C:\Documents and Settings\Administrator.DDNETTEST\My Documents\RecBt.java:57: Method getWidth() not found in inner class RecBt. DPanel. g.drawImage(image,0,h2,getWidth(),h2,null); ^ 4 errors