
I have loaded two images using toolkit in java.one is concentric rectangle and other is concentric circle.kindly someone send me the source code of interchanging the inner most rectangle with the inner most circle and inner circle with inner rectangle.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class DrawRectAndCir extends JPanel{
public void paint( Graphics g ) {
g.drawOval (50, 10, 220, 220);
g.drawOval (70, 30, 180, 180);
g.drawOval (90, 50, 140, 140);
g.drawOval (110, 70, 100, 100);
g.drawOval (130, 90, 60, 60);
g.drawRect (150, 110, 20, 20);
g.drawRect (300, 10, 300, 220);
g.drawRect (320, 30, 260, 180);
g.drawRect (340, 50, 220, 140);
g.drawRect (360, 70, 180, 100);
g.drawRect (380, 90, 140, 60);
g.drawOval (400, 110, 100, 20);
}
}
public class DrawConcentricRectangleAndCircles extends JPanel {
public void paint(Graphics g) {
g.drawOval (50, 10, 220, 220);
g.drawOval (70, 30, 180, 180);
g.drawOval (90, 50, 140, 140);
g.drawOval (110, 70, 100, 100);
g.drawOval (130, 90, 60, 60);
g.drawOval (150, 110, 20, 20);
g.drawRect (300, 10, 300, 220);
g.drawRect (320, 30, 260, 180);
g.drawRect (340, 50, 220, 140);
g.drawRect (360, 70, 180, 100);
g.drawRect (380, 90, 140, 60);
g.drawRect (400, 110, 100, 20);
}
public static void main(String s[]) {
final JFrame frame = new JFrame("Show Triangle");
final JPanel p = new DrawConcentricRectangleAndCircles();
final JPanel p1=new DrawRectAndCir();
JButton b=new JButton("Convert");
b.setSize(100,20);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
p.setVisible(false);
frame.getContentPane().add("Center", p1);
p1.setVisible(true);
}
});
p1.setVisible(false);
frame.getContentPane().add("Center", p);
frame.getContentPane().add("South", b);
frame.setSize(650,320);
frame.show();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.