Question #12
Prepare an applet called FourCorners. Draw a circle in the top left corner; an oval in the bottom right; a rectangle in the top right and a line in the bottom left. Put you're name centered on the applet. The program is started below. Please remember to include You're code in reply and a screen shot.:
import.java.applet.*;
import.java.awt.*;
public class FourCorners extends Applet
{
public void paint(Graphics g)
{
g.fillOval(0,0,50,50);
I don't see what the problem is here. The problem is practically solved for you already.
The circle is already drawn (that's the oval with the same height and widht).
The oval can be drawn the same way, but by varying the height and width from each other.
The rectangle can be done with the fillRect method of g
The line can be drawn with the drawLine method of g.
Your name can be put in place with the drawString method of g.
so all you really need to do is determine WHERE to put the components, which is simple geometry.
if you need help with the parameters for those methods, you should consult the API for Graphics. I'm not going to supply you with those. You need to do SOME of this homework for yourself.
> Prepare an applet called FourCorners. Draw a circlein the top left
> corner; an oval in the bottom right; a rectangle in the top right and a
> line in the bottom left. Put you're name centered on the applet. The
> program is started below. Please remember to include You're code in
> reply and a screen shot.:
No, my religion forbids me to do that.
kind regards,
Jos
JosAHa at 2007-7-13 23:32:48 >

There, there now! Don't let those nasty people upset you. This code is exactly what you need.import javax.swing.*;
import java.awt.*;
public class Question12 extends JPanel
{
public Question12()
{
GridBagConstraints c = new GridBagConstraints();
GridBagConstraints end;
JPanel panel;
JLabel label = new JLabel();
Font labelFont = label.getFont().deriveFont(Font.BOLD + Font.ITALIC, 60.0F);
// Set constraints for panel
c.weightx = 1;
c.weighty = 1;
end = (GridBagConstraints) c.clone();
end.gridwidth = GridBagConstraints.REMAINDER;
// Set layout for panel
setLayout(new GridBagLayout());
// add top left (circle)
panel = new JPanel();
label = new JLabel(揬u0044\u004F?;
label.setFont(labelFont);
panel.add(label);
add(panel, c);
// add top center (empty)
panel = new JPanel();
add(panel, c);
// add top right (rectangle)
panel = new JPanel();
label = new JLabel(揬u0059\u004F\u0055\u0052?;
label.setFont(labelFont);
panel.add(label);
add(panel, end);
// add middle left (empty)
panel = new JPanel();
add(panel, c);
// add middle center (your name)
panel = new JPanel();
panel.add(new JLabel(?your name here)?);
add(panel, c);
// add middle right (empty)
panel = new JPanel();
add(panel, end);
// add bottom left (line)
panel = new JPanel();
label = new JLabel(揬u004F\u0057\u004E?;
label.setFont(labelFont);
panel.add(label);
add(panel, c);
// add bottom center (empty)
panel = new JPanel();
add(panel, c);
// add bottom right (oval)
panel = new JPanel();
label = new JLabel(揬u0048\u004F\u004D\u0045\u0057\u004F\u0052\u004B\u0021?;
label.setFont(labelFont);
panel.add(label);
add(panel, end);
}
public static void main(String args[])
{
JFrame mainFrame = new JFrame();
mainFrame.getContentPane().add(new Question12());
mainFrame.setSize(new Dimension(640, 400));
mainFrame.setVisible(true);
// So you can close the application
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}