Showing posts with label current. Show all posts
Showing posts with label current. Show all posts

Get current second

Complete source code below, will show you how to get current computer second and print the value. The second value that it get is second value at program executing time.

>>Get current minute
>>Get current hour
>>Get current computer time in java

******************************************************************
COMPLETE SOURCE CODE FOR : GetCurrentSecond.java
******************************************************************


import java.util.Date;

public class GetCurrentSecond
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current second
int currentSecond=myDate.getSeconds();

//Print current second that we get
System.out.println("Current second is : "+currentSecond);
}
}


******************************************************************
JUST COMPILE AND EXECUTE IT
******************************************************************

Get current minute

Complete source code below will print current computer minute.

>>Get current second
>>Get current hour
>>Get current computer time in java

*******************************************************************
COMPLETE SOURCE CODE FOR : GetCurrentMinute.java
*******************************************************************


import java.util.Date;

public class GetCurrentMinute
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current minute
int currentMinute=myDate.getMinutes();

//Print current minute that we get
System.out.println("Current minute is : "+currentMinute);
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

Get current hour

Complete source code below will print current computer hour in soldier time format.Soldier time format is 24 hour format.

>>Get current minute
>>Get current second
>>Get current computer time in java

**************************************************************
COMPLETE SOURCE CODE FOR : GetCurrentHour.java
**************************************************************


import java.util.Date;

public class GetCurrentHour
{
public static void main(String[]args)
{
Date myDate=new Date();

//Get current hour in soldier time format
int currentHour=myDate.getHours();

//Print current hour that we get
System.out.println("Current hour is : "+currentHour);
}
}


**************************************************************
JUST COMPILE AND EXECUTE IT
**************************************************************

Get current computer time in java

Complete source code below will show you, how to get current computer time in java.

*******************************************************************
COMPLETE SOURCE CODE FOR : GetCurrentTime.java
*******************************************************************


import java.util.Date;

public class GetCurrentTime
{
public static void main(String[]args)
{
Date myDate=new Date();

System.out.println(myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds());
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

Compare current date with user input date in java

Complete source code below will show you, how to compare current date with user input date in java.

***************************************************************************
COMPLETE SOURCE CODE FOR : GetDate.java
***************************************************************************


import java.util.Date;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class GetDate implements ActionListener
{
int year=0;
int month=0;
int date=0;

String [] yearContent={"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011"};
String [] monthContent={"January","February","March","April","Mei","Jun","July","August","September","October","November","December"};
String [] dateContent={"1","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30",
"31"};

JComboBox yearComboBox=new JComboBox(yearContent);
JComboBox monthComboBox=new JComboBox(monthContent);
JComboBox dateComboBox=new JComboBox(dateContent);

JButton button=new JButton("Click here to compare to current date");

JFrame frame=new JFrame("Compare date with current date");

public GetDate()
{
button.addActionListener(this);

Box box=Box.createHorizontalBox();
box.add(dateComboBox);
box.add(monthComboBox);
box.add(yearComboBox);

frame.setLayout(new GridLayout(2,1));

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(box);
frame.add(button);
frame.setSize(500,100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==button)
{
String tempDate=(String)dateComboBox.getSelectedItem();
date=Integer.parseInt(tempDate);

month=monthComboBox.getSelectedIndex();

String tempYear=(String)yearComboBox.getSelectedItem();
year=Integer.parseInt(tempYear)-1900;

Date currentDateValue=new Date();
Date userChooserDate=new Date(year,month,date);

int currentYear=currentDateValue.getYear();
int currentMonth=currentDateValue.getMonth();
int currentDate=currentDateValue.getDate();

if((date==currentDate)&&(month==currentMonth)&&(year==currentYear))
{
JOptionPane.showMessageDialog(frame,"Same date","SAME",JOptionPane.INFORMATION_MESSAGE);
}
else if(userChooserDate.compareTo(currentDateValue)<0)>0)
{
JOptionPane.showMessageDialog(frame,"Welcome to the future","FUTURE",JOptionPane.INFORMATION_MESSAGE);
}
}
}

public static void main(String[]args)
{
GetDate gd=new GetDate();
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************

Get current cursor location in JTextArea

Complete source code below will show you, how to get current cursor location in JTextArea.

***********************************************************************
COMPLETE SOURCE CODE FOR : GetCurrentCursorLocationInJTextArea.java
***********************************************************************


import javax.swing.*;

import java.awt.event.*;

import java.awt.*;

public class GetCurrentCursorLocationInJTextArea extends JTextArea implements MouseMotionListener
{
//Create window using JFrame with title ( Get current cursor location in JTextArea )
JFrame frame=new JFrame("Get current cursor location in JTextArea");

//Create text field that will show you, current cursor location
JTextField textFieldX=new JTextField(5);
JTextField textFieldY=new JTextField(5);

//Create label that will use to describe function for each text field
JLabel labelX=new JLabel("Coordinate X : ");
JLabel labelY=new JLabel("Coordinate Y : ");

//Create panel that will use to store text field and label
JPanel panelX=new JPanel();
JPanel panelY=new JPanel();

//Panel that will use to store panelX and panelY
JPanel container=new JPanel();

public GetCurrentCursorLocationInJTextArea()
{
//Add mouse motion listener to JTextArea
addMouseMotionListener(this);

//Set container layout using BorderLayout
container.setLayout(new BorderLayout());

//Set panelX and panelY layout using GridLayout
panelX.setLayout(new GridLayout(1,2));
panelY.setLayout(new GridLayout(1,2));

//Add labelX and textFieldX into panelX
panelX.add(labelX);
panelX.add(textFieldX);

//Add labelY and textFieldY into panelY
panelY.add(labelY);
panelY.add(textFieldY);

//Add panelX and panelY into container
container.add(panelX,BorderLayout.WEST);
container.add(panelY,BorderLayout.EAST);

//Set frame layout using BorderLayout
frame.setLayout(new BorderLayout());

//Add JTextArea into JFrame
frame.add(this,BorderLayout.CENTER);

//Add container into JFrame
frame.add(container,BorderLayout.SOUTH);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setVisible(true);
}

public void mouseMoved(MouseEvent event)
{
//Get current X-coordinate for cursor
textFieldX.setText("");
textFieldX.setText(Integer.toString(event.getX()));

//Get current Y-coordinate for cursor
textFieldY.setText("");
textFieldY.setText(Integer.toString(event.getY()));
}

public void mouseDragged(MouseEvent event)
{
//Do nothing because our case not handle dragging
}

public static void main(String[]args)
{
GetCurrentCursorLocationInJTextArea gcclijta=new GetCurrentCursorLocationInJTextArea();
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

Source code to determine display mode for current screen can change or not using java


***********************************************************
COMPLETE SOURCE CODE FOR : DetermineDisplayModeCanChangeOrNot.java
***********************************************************


import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;

public class DetermineDisplayModeCanChangeOrNot
{
public static void main(String[]args)
{
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd=ge.getDefaultScreenDevice();

//METHOD isDisplayChangeSupported() returns true if this GraphicsDevice supports low-level display changes.
boolean change=gd.isDisplayChangeSupported();

if(change==true)
{
System.out.println("DISPLAY MODE CAN CHANGE");
}

else
{
System.out.println("DISPLAY MODE CANNOT CHANGE");
}
}
}


***********************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************

Current refresh rate


*****************************************************************
COMPLETE SOURCE CODE FOR : RefreshRateForCurrentScreen.java
*****************************************************************


import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.DisplayMode;

public class RefreshRateForCurrentScreen
{
public static void main(String[]args)
{
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd=ge.getDefaultScreenDevice();
DisplayMode dm=gd.getDisplayMode();

//Print refresh rate for current screen
System.out.println("REFRESH RATE FOR CURRENT SCREEN : "+dm.getRefreshRate());
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Current bit depth


*******************************************************************
COMPLETE SOURCE CODE FOR : CurrentBitDepth.java
*******************************************************************


import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;

import java.awt.DisplayMode;

public class CurrentBitDepth
{
public static void main(String[]args)
{
//HOW TO GET CURRENT SCREEN BIT DEPTH

GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd=ge.getDefaultScreenDevice();
DisplayMode dm=gd.getDisplayMode();

//Print current bit depth
System.out.println("CURRENT SCREEN BIT DEPTH IS: "+dm.getBitDepth());
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

How to know current location of jframe after it moved to other location on screen


Result of the current location for a jframe in this program is current coordinate of the top left corner for the jframe.

********************************************************************
COMPLETE SOURCE CODE FOR : HowToKnowCurrentLocationOfJframe.java
********************************************************************


import javax.swing.JFrame;
import javax.swing.JOptionPane;

import java.awt.event.ComponentListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import java.awt.Point;
import java.awt.Component;

public class HowToKnowCurrentLocationOfJframe extends ComponentAdapter
{
JFrame b=new JFrame("TRY MOVE ME");

public HowToKnowCurrentLocationOfJframe()
{
b.addComponentListener(this);

b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setSize(400,100);
b.setVisible(true);
}

public void componentMoved(ComponentEvent evt)
{
Component temp=(Component)evt.getSource();
JOptionPane.showMessageDialog(null,"CURRENT LOCATION : "+" X = "+(temp.getLocationOnScreen()).getX()+" Y = "+(temp.getLocationOnScreen()).getY(),"CURRENT LOCATION",JOptionPane.INFORMATION_MESSAGE);
}

public static void main(String[]args)
{
HowToKnowCurrentLocationOfJframe myObject=new HowToKnowCurrentLocationOfJframe();
}
}


********************************************************************
JUST COMPILE AND EXECUTE IT
********************************************************************

RELAXING NATURE VIDEO