article

Showing posts with label Java-Swing. Show all posts
Showing posts with label Java-Swing. Show all posts

Wednesday, July 3, 2019

Java Swing jRadioButton Usage Tutorial


Java Swing jRadioButton Usage Tutorial
 
private void formWindowOpened(java.awt.event.ActionEvent evt)
  bgroup1.add(radiolicense);  
  bgroup1.add(radiolicense);
}

private void radiolicensePerformed(java.awt.event.ActionEvent evt) {
  cmdsubmit.setEnable(true);
}
private void radiolicensePerformed(java.awt.event.ActionEvent evt) {
  cmdsubmit.setEnable(false);
}
//=====================================
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String qual = "";
        if (jRadioButton1.isSelected()){
            qual = "Your Under Graduate";
        }else{
            qual = "Graduate";
        }
        JOptionPane.showMessageDialog(rootPane, qual);
    }

Tuesday, July 2, 2019

Java Swing JPasswordField & JCheckBox Usage - Login Example Tutorial

Java Swing JPasswordField & JCheckBox Usage - Login Example Tutorial
 
private void cmdloginActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if (txtusername.getText().equalsIgnoreCase("test") && txtpass.getText().equalsIgnoreCase("123")){
            if (chkremember.isSelected()){
                lblmessage.setText("Login successful with remembering option");
            }else{
                lblmessage.setText("Login successful without remembering option");
            }
        }else{
            lblmessage.setText("Login Failed");
        } 
    }
private void cmdloginActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        String userName =  txtusername.getText();
        String password =  txtpass.getText();
        if (userName.trim().equals("admin") && password.trim().equals("admin")) {
            lblmessage.setText("Hello" + userName +"");
        }else{
            lblmessage.setText("Invalid User");
        }
    }                                        

    private void cmdresetActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         lblmessage.setText("");
         txtusername.setText("");
         txtpass.setText("");
    } 

Monday, July 1, 2019

Java Swing Tutorial JTextField Usage Using Netbeans IDE

Java Swing Tutorial JTextField Usage Using Netbeans IDE
 
private void cmdsubmitActionPerformed(java.awt.event.ActionEvent evt) {
  String message = "Hello,"+txtname.getText();
  lblmessagedisplay.setText(message);
}

private void cmdsubmitActionPerformed(java.awt.event.ActionEvent evt) {
    int a=Integer.parseInt(x);
 String y=(String) jComboBox1.getSelectedItem();
 int b=Integer.parseInt(y);
 int r=a*b;
 String z=Integer.toString(r);
 txtresult.setText(z);
}

private void cmdsubmitActionPerformed(java.awt.event.ActionEvent evt) {
 String s1=tf1.getText();
 String s2=tf2.getText();
 int a=Integer.parseInt(s1);
 int b=Integer.parseInt(s2);
 int c=0;
 c=a+b;
 String result=String.valueOf(c);
 tf3.setText(result);
}

Sunday, June 30, 2019

Java Swing if else statement using Netbeans IDE

Java Swing if else statement using Netbeans IDE
 
public static void main(String args[]) {
 String input = JOptionPane.showInputDialog("Enter your age");
 int aga = Integer.parseInt(input);
 if (age >=18){
   JOptionPane.showMessageDialog(null,"You are an adult");
 }else{
   JOptionPane.showMessageDialog(null,"You are a minor");
 }
 /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JTextField_JFrame().setVisible(true);
            }
        });
}
 
public static void main(String args[]) {
 int side1 = Integer.parseInt(JOptionPane.showInputDialog("Enter the first side"));
 int side2 = Integer.parseInt(JOptionPane.showInputDialog("Enter the second side"));
 int side3 = Integer.parseInt(JOptionPane.showInputDialog("Enter the third side"));

 if (side1 == side2 && side2 == side3){
    JOptionPane.showMessageDialog(null,"It is an equilateral triangle");
 }else{
   if (side1 == side2 || side2 == side3) {
   JOptionPane.showMessageDialog(null,"It is an isosceles triagle")
   }else{
   JOptionPane.showMessageDialog(null,"It is an scalene triagle")
   }
 }
 
 /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JTextField_JFrame().setVisible(true);
            }
        });
}

How to create simple Java Swing GUI with Netbeans IDE

How to create simple Java Swing GUI with Netbeans IDE


 
    private void cmdsubmitbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdsubmitbuttonActionPerformed
        // TODO add your handling code here:
        String name = JOptionPane.showInputDialog("Type your name please");
        JOptionPane.showMessageDialog(null, "Hello " + name);
        //JOptionPane.showMessageDialog(null, "Hello World");
    }//GEN-LAST:event_cmdsubmitbuttonActionPerformed

Friday, June 10, 2016

Java Swing


Java Swing

Swing is the principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java programs. It is completely written in Java.
 
package com.tutorial101;

import java.awt.EventQueue;
import javax.swing.JFrame;

public class SimpleEx extends JFrame {

    public SimpleEx() {

        initUI();
    }

    private void initUI() {
        
        setTitle("Simple example"); //window title
        setSize(300, 200); //size window
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {

        EventQueue.invokeLater(new Runnable() { //This method will close the window if we click on the close button of the titlebar
        
            @Override
            public void run() {
                SimpleEx ex = new SimpleEx();
                ex.setVisible(true);
            }
        });
    }
}

Related Post