As you can quickly guess, im new to java- I need help getting this circle to appear when my circle button is pressed... I need the class headers to remain the same (unless adding extends or implements) because this is actually a piece of an assignment.
I've been trying for hours and hours, but I cant get anything to appear!
drawMain.java
I've been trying for hours and hours, but I cant get anything to appear!
drawMain.java
myFrame.javaimport javax.swing.*;
public class drawMain {
public drawMain() {
myFrame frame = new myFrame();
frame.setVisible(true);
}
static public void main(String[] args) {
new drawMain();
}
}
myShape.javaimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.lang.Integer;
public class myFrame extends JFrame implements ActionListener {
JButton jButtonCir = new JButton();
JPanel myPanel = new JPanel();
public myFrame() {
jButtonCir.setLocation(160, 320);
jButtonCir.setSize(110, 40);
jButtonCir.setVisible(true);
jButtonCir.setText("Circle");
jButtonCir.addActionListener(this);
myPanel.setBackground(Color.white);
myPanel.setLocation(10, 10);
myPanel.setSize(433,295);
myPanel.setVisible(true);
getContentPane().add(jButtonCir);
getContentPane().add(myPanel);
getContentPane().setLayout(null);
setLocation(0, 0);
setTitle("myFrame");
setSize(460, 480);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});
}
public void actionPerformed( ActionEvent ae) {
if(ae.getSource()==jButtonCir){
myCircle circle=new myCircle(50,50);
circle.setLocation(0,0);
circle.setVisible(true);
getContentPane().add(circle);
System.out.println("button pressed");
}
}
}
myCircle.javaimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public abstract class myShape extends JComponent {
public myShape(){
super();
}
}
import java.awt.*;
import javax.swing.*;
public class myCircle extends myShape{
int shapeWidth;
int shapeHeight;
public myCircle(int w, int h){
super();
shapeWidth=w;
shapeHeight=h;
System.out.println("in myCircle constructor");
}
public void paintComponent(Graphics g){
super.paintComponent(g);
System.out.println("in the paint component");
g.setColor(Color.red);
g.fillOval(0,0,shapeWidth,shapeHeight);
}
}