Found 9150 Articles for Object Oriented Programming

Java sql.Timestamp valueOf() method with example

Rishi Raj
Updated on 30-Jul-2019 22:30:26

1K+ Views

The valueOf() method of the java.sql.Timestamp class accepts a String value representing a time stamp in JDBC escape format and converts the given String value into Timestamp object.Timestamp timeStamp = Time.valueOf("timeStamp_string");ExampleLet us create a table with name dispatches_data in MySQL database using CREATE statement as shown below:CREATE TABLE dispatches_data(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchTimeStamp timestamp,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches_data table using INSERT statements:insert into dispatches_data values('Key-Board', 'Raja', TIMESTAMP('2019-05-04', '15:02:45'), 7000, 'Hyderabad'); insert into dispatches_data values('Earphones', 'Roja', TIMESTAMP('2019-06-26', '14:13:12'), 2000, 'Vishakhapatnam'); insert into dispatches_data values('Mouse', 'Puja', TIMESTAMP('2019-12-07', '07:50:37'), 3000, 'Vijayawada'); insert into ... Read More

How to close JFrame on the click of a Button in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

13K+ Views

Set frame.dispose() on the click of a button to close JFrame. At first create a button and frame −JFrame frame = new JFrame(); JButton button = new JButton("Click to Close!");Now, close the JFrame on the click of the above button with Action Listener −button.addActionListener(e -> {    frame.dispose(); });The following is an example to close JFrame on the click of a Button −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Click to Close!");   ... Read More

Java Program to display Frame after some seconds

karthikeya Boyini
Updated on 02-Jan-2025 19:13:28

414 Views

In this article, we will learn how to display a frame after a few seconds in Java using the Timer class. This example shows how to delay the visibility of a frame by 2 seconds using Swing. Timer() class The Timer class is used to schedule tasks that execute after a specific time interval or repeatedly at regular intervals. It allows tasks to be run by a thread that handles the scheduling and execution. Each task can be set to execute either once or repeatedly at fixed intervals. The execution of all tasks is managed by a background thread associated ... Read More

How to change JFrame background color in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

23K+ Views

At first, create a JFrame −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(550, 300));Now, change the background color of the JFrame −frame.getContentPane().setBackground(Color.BLUE);The following is an example to change JFrame background color −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setPreferredSize(new Dimension(550, 300));       frame.getContentPane().setBackground(Color.BLUE);       frame.pack();       frame.setVisible(true);    } }Output

How can we set Mnemonic Key Radio Button in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

490 Views

Mnemonic key is set so that a user can use Keyboard keys to select a Radio Button. For example, a key can be set with ALT −radio2.setMnemonic(KeyEvent.VK_R);Above, we have set key ALT+R for radio2.The following is an example to set Mnemonic key radio button −package my; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; public class SwingDemo {    public static void main(String[] args) {       JRadioButton radio1 = new JRadioButton("Male");       JRadioButton radio2 = new JRadioButton("Female");       radio2.setMnemonic(KeyEvent.VK_R);       ButtonGroup group = new ButtonGroup();       ... Read More

Java Program to create a vertical ProgressBar

Alshifa Hasnain
Updated on 24-Dec-2024 17:55:32

542 Views

In this article, we will learn about creating a vertical progress bar using JProgressBar.VERTICAL in Java. Progress bars are essential for tracking task completion in GUI applications, and a vertical orientation can add a unique touch to your design. What is a Progress Bar in Java Swing? A progress bar is a visual component in Java Swing that indicates the progress of a task. It can be horizontal or vertical, depending on the application's design requirements. Java Swing provides the JProgressBar class to create and manage progress bars efficiently. Features of a Vertical Progress Bar The following are features of ... Read More

Set Bounds for JProgressBar in Java Swing

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

375 Views

Use the setBounds() method to set Bounds for JProgressBar in Java Swing −JProgressBar progressBar; progressBar.setBounds(70, 50, 120, 30);The following is an example to set bounds for JProgressBar −Examplepackage my; import javax.swing.*; public class SwingDemo extends JFrame {    JProgressBar progressBar;    int i = 0;    SwingDemo() {       progressBar = new JProgressBar(0, 1000);       progressBar.setBounds(70, 50, 120, 30);       progressBar.setValue(0);       progressBar.setStringPainted(true);       add(progressBar);       setSize(550, 150);       setLayout(null);    }    public void inc() {       while (i

How to disable a JLabel in Java?

Samual Sam
Updated on 30-Jul-2019 22:30:26

518 Views

To disable a JLabel, use the setEnabled() method −JLabel label; label.setEnabled(false);The following is an example to disable a JLabel −package my; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("First Label", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setPreferredSize(new Dimension(250, 100));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new Color(100, 20, 70));       label.setEnabled(false);   ... Read More

How to change JLabel size in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

9K+ Views

With Java Swing, you can set JLabel size as preferred size different than the default −JLabel label.setPreferredSize(new Dimension(250, 100));The following is an example to change JLabel size −Exampleimport java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This is demo label!", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setPreferredSize(new Dimension(250, 100));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new ... Read More

Java sql.Timestamp toString() method with example

Rishi Raj
Updated on 30-Jul-2019 22:30:26

7K+ Views

The toString() method of the java.sql.Timestamp class returns the JDBC escape format of the time stamp of the current Timestamp object as String variable.i.e. using this method you can convert a Timestamp object to a String.//Retrieving the Time object Timestamp timestampObj = rs.getTimestamp("DispatchTimeStamp"); //Converting the Time object to String format String time_stamp = timestampObj.toString();ExampleLet us create a table with the name dispatches_data in MySQL database using CREATE statement as shown below:CREATE TABLE dispatches_data(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchTimeStamp timestamp,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches_data table using INSERT statements:insert into ... Read More

Advertisements