How to set application first open date in same system using java netbeans

211 views Asked by At

I want to create a small application for that purpose I want to know how to set a date in jLabel which was open the application first time in that system using java netbeans.

2

There are 2 answers

2
Ravindra Ranwala On BEST ANSWER

Try this out in your main method. Read the starting date from a property file.

package com.java.demo;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Test {

    public static void main(String[] args) {
        JFrame frame = new JFrame("Test Frame");
        frame.setLayout(new GridBagLayout());

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setPreferredSize(new Dimension(250, 150));
        frame.setMaximumSize(new Dimension(250, 150));
        frame.setMinimumSize(new Dimension(250, 150));
        JLabel label = new JLabel(new Date().toString());
        frame.getContentPane().add(label);
        frame.setVisible(true);

    }

}

Hope this helps. Happy Coding !

3
Timothy Truckle On

There is no such possibility (independent of the programming language or the IDE you use).

The reason is that you'd need administrator rights to store that information at a place where all users of the system have assess to and which is not likely to be deleted by accident.

You would need an installer to store that information at such place.


But If you have that you could read that file containing that information. the basic technique to do so is a FileReader or the Scanner class from the Java standard lib, but if your "system config" gets more complex you might change to some mapping framework.