Hi Experts,
I have question on the bellow program (runs perfectly),
1. As I have created an instance (object) of startup class and we dint called method paint from the main method using the object but still it is called (how?). But in case of Instantiable classes, we need to call any method explicitly using the created object.
2. Is there any standard sheet to do rough calculation of frame locations? It is bit confusing, because my window resolution is 1024*768 and my frame size is differs. Whatever location measurement we do with frames: Is it depends on Window resolution or Frame resolution?


Thanks in advance for any help!

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import java.io.File;
import java.util.Enumeration;
import java.util.Set;

public class TestSheet 
{
    public static void main(String args[]) throws Exception
    {
        File f = new File("F://my study material//DemoFiles//DemoTXT.txt");
        FileOutputStream fout = new FileOutputStream("F://my study material//DemoFiles//DemoTXT2.txt", true);
        FileInputStream fis = new FileInputStream(f);
        Properties p = new Properties();
        p.load(fis);
        Enumeration e = p.propertyNames();

        while(e.hasMoreElements())
        {
            String key = (String)e.nextElement();
            System.out.println(key + " : \t" + p.getProperty(key));
        }
        p.store(fout, "no comment");

        System.out.println();
        Set subject = p.keySet();

        for(Object name: subject)
            System.out.println(name+" : "+p.getProperty((String)name));

        String str = p.getProperty("Social Science", "No record");
        System.out.println("Marks obtain by social science: "+str);

        
    }
   
}

Jiten

What Object does paint() get called on? I see no GUI code...

Extremely sorry, I have made a mistake. mistakenly posted the wrong code!
Here the correct code:

import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Color;


public class DrawOnFrame extends Frame
{
    DrawOnFrame()
    {
        this.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
    }
    public void paint(Graphics g)
    {
        //set blue color for drawing
        g.setColor(Color.blue);

        //displaya rectangle to contain drawing
        g.drawRect(40, 40, 200, 200);

        //draw face
        g.drawOval(90, 70, 80, 80);

        //eyes
        g.drawOval(110, 95, 5, 5);
        g.drawOval(145, 95, 5, 5);

        //nose
        g.drawLine(130, 95, 130, 115);

        //mouth
        g.drawArc(113,115,35,20,0,-180);


    }
    public static void main(String args[])
    {
        //create the frame
        DrawOnFrame d = new DrawOnFrame();

        //set title, size and visibility
        d.setTitle("My Frame");
        d.setSize(400, 400);
        d.setVisible(true);


        
    }

}

The paint() method is called by setVisible(), and since you called setVisible(), paint was called indirectly. As far as your other question, you'll need to clarify what you mean: are you trying to figure out how large your monitor is and make the Frame cover the entire monitor?

mean, when we work on frame or applet we give locations(x and y coordinates, width, heigth etc.) for components, containers (buttons, checkboxes, radiobotton, text input area etc.. My questions is when when working with such things is that we have to imagine the location and assign or is there a standard sheet to do rough drawing ?
Thanks
Jiten

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.