Results 1 to 2 of 2
Thread: Grid Layout with paintComponent
- 03-06-2010, 01:14 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
Grid Layout with paintComponent
I can't seem to figure out how to get one copy of each of my paintComponent in each of the six grid squares. I can get 6 buttons to work but not 6 images. Any help would be greatly appreciated. Here is my code:
FILE1:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author compuser
*/
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class Project6 extends JFrame {
public Project6() {
Container cp=this.getContentPane();
cp.setBackground(Color.WHITE);
cp.setLayout(new BorderLayout());
YingYang md=new YingYang();
BorderLayout bl =new BorderLayout();
cp.setLayout(bl);
JTextField text= new JTextField("Hello");
cp.add(text, BorderLayout.SOUTH);
Date date = new Date();
text.setText(date.toString());
this.setTitle("Project62");
JPanel panel=new JPanel();
cp.add(panel, BorderLayout.CENTER);
panel.setLayout(new GridLayout(2, 3));
for (int i=0; i<6; i++ ) {
panel.add(md);
}
}
public static void main(String[] args) {
JFrame frame=new Project6();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setBounds(200, 100, 500, 400);
frame.setVisible(true);
}
}
FILE2:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author compuser
*/
import javax.swing.*;
import java.awt.*;
public class YingYang extends JPanel {
int a;
int b;
public YingYang() {
a=300;
b=200;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.WHITE);
g.fillArc(100, 100, 100, 100, 90, -180);
g.setColor(Color.BLACK);
g.fillArc(100, 100, 100, 100, 90, 180);
g.setColor(Color.BLACK);
g.fillOval(125, 100, 50, 50);
g.setColor(Color.WHITE);
g.fillOval(125, 150, 50, 50);
}
}
- 03-06-2010, 01:20 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Similar Threads
-
paintComponent is not working
By spazattack in forum New To JavaReplies: 1Last Post: 12-18-2009, 03:48 AM -
Grid layout frames GUI
By fritz1474 in forum AWT / SwingReplies: 1Last Post: 10-15-2008, 02:04 AM -
Problem going outside paintComponent
By Thez in forum Java 2DReplies: 9Last Post: 12-08-2007, 04:59 PM -
Drawing outside paintComponent()
By DarkSide1 in forum Java 2DReplies: 2Last Post: 11-08-2007, 10:36 PM -
Help with Grid Layout
By coco in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks