How to create an object of another class in main()?

J

Jenny

Hi,

In the code below, what should be in the place marked by ??? in main()? Thanks.

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class TryFont2 extends JFrame {
RectPanel r;
public TryFont2() {
super("Rectangles");
setSize(410, 430);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
setContentPane(content);
setVisible(true);
}

public static void main(String[] arguments) {
TryFont2 rect = new TryFont2();
rect.r = new ???;
}
class RectPanel extends JPanel {
public Graphics2D comp2D;
public void paintComponent(Graphics comp) {
super.paintComponent(comp);
comp2D = (Graphics2D) comp;
setBackground(Color.white);
comp2D.rotate(-.4,200,200);
Font f1 = new Font("Times New Roman",Font.BOLD,40);
comp2D.setColor(Color.green);
comp2D.setFont(f1);
comp2D.drawString("Happy",50,150);
comp2D.setColor(Color.red);
comp2D.drawString("Birthday!",50,200);
}}
 
P

Paul Lutus

Jenny said:
Hi,

In the code below, what should be in the place marked by ??? in main()?

That depends on what you intended to put there. Nearly anything.

Follow this recipe:

1. I expected ____________________
2. But darn, instead I got ______________________
3. Here is EXACTLY how (2) differs from (1), with nothing left to the
imagination _______________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top