How would I go about using swing components and graphics in the same program. Whenever I seem to add a swing component my graphics disappear. Please help. Thanks.
My main Class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ResistorColorCodeProgram implements MouseMotionListener, MouseListener, KeyListener{
public ResistorColorCodeProgram (){
JFrame resistorCCFrame = new JFrame ("Resistor Color Code");
resistorCCFrame.setBackground (Color.white);
resistorCCFrame.setSize(600,500);
JPanel resistorCCPanel = new JPanel ();
resistorCCFrame.setLayout(new BorderLayout ());
JPanel pane = new JPanel ();
JButton b = new JButton ("Test");
resistorCCFrame.add("North", pane);
resistorCCFrame.add(pane);
resistorCCFrame.setVisible(true);
ResistorColorCodeGraphics rCCG = new ResistorColorCodeGraphics ();
rCCG.ColorCodeDraw ();
resistorCCFrame.add("Center",rCCG);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ResistorColorCodeProgram rccp = new ResistorColorCodeProgram ();
}
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
My Graphics Class
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class ResistorColorCodeGraphics extends JFrame{
Image base, black, brown, red, orange, yellow, green, blue, violet, gray, white;
public void ColorCodeDraw (){
base = getToolkit().getImage("ResistorCCImages\\Resistor Base.gif");
/*black = new Image ("Black Ring.gif");
brown = new Image ("Brown Ring.gif");
red = new Image ("Red Ring.gif");
orange = new Image ("Orange Ring.gif");
yellow = new Image ("Yellow Ring.gif");
green = new Image ("Green Ring.gif");
blue = new Image ("Blue Ring.gif");
violet = new Image ("Violet Ring.gif");
gray = new Image ("Gray Ring.gif");
white = new Image ("White Ring.gif");
*/
repaint();
}
public void paint (Graphics g){
super.paintComponents(g);
g.drawImage(base, 100, 100, 300, 150, this);
}
}
again. Thanks for any help.