public class ShowBoxes extends JFrame { public ShowBoxes() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); JPanel p1 = new MyBox(0, 0, 50, 50); p1.setForeground(Color.red); getContentPane().add(p1, BorderLayout.NORTH); JLabel lbl2 = new JLabel("tekst"); getContentPane().add(lbl2, BorderLayout.CENTER); JPanel p3 = new MyBox(0, 0, 50, 50); p3.setForeground(Color.blue); getContentPane().add(p3, BorderLayout.SOUTH); pack(); } public static void main(String[] args) { ShowBoxes f = new ShowBoxes(); f.show(); } }
class MyBox extends JPanel { private int x, y, w, h; public MyBox(int x, int y, int w, int h) { this.x = x; this.y = y; this.w = w; this.h = h; } public void paintComponent(Graphics g) { g.fillRect(x, y, w, h); } }
når jeg skriver cd "Documents and Settings" siger den syntax er forkert... er det ikke rigtigt? eller er det alt for LAAAANG tid siden jeg har roddet med Dos
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.