VB.Net Get Mouse Coordinates

How To Get Cursor Position In Visual Basic .Net

vbnet cursor position


In This VB.NET Tutorial We Will See How To Get Mouse Coordinates [X ; Y] 
Using Visual Basic .NET Programming Language.


Project Source Code:

Public Class VB_MouSE_CR
    Private Sub VB_MouSE_CR_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick

        Label1.Text = "X = " & e.X & " ; Y = " & e.Y

    End Sub

    Private Sub VB_MouSE_CR_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove

        Label1.Text = "X = " & e.X & " ; Y = " & e.Y

    End Sub
End Class

///////////////OUTPUT:

visual basic.net cursor xy position







C# Get Mouse Coordinates

How To Get Cursor Position In C# 


c# cursor position


In This C# Tutorial  We Will See How To Get Mouse Coordinates [X ; Y] In CSharp Programming Language.


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class FormMouseCR : Form
    {
        public FormMouseCR()
        {
            InitializeComponent();
        }

        private void FormMouseCR_MouseClick(object sender, MouseEventArgs e)
        {
            label1.Text = "X = " + e.X + " ; Y = " + e.Y;
        }

        private void FormMouseCR_MouseMove(object sender, MouseEventArgs e)
        {
            label1.Text = "X = " + e.X + " ; Y = " + e.Y;
        }

    }
}


// OUTPUT :


c# get cursor position




Java Load And Clear JTable Data

How To Add And Remove All JTable Rows In Java

java load and remove jtable data



In this Java Tutorial we will see How To Populate And Delete JTabe Content In Java Using NetBeans .




Project Source Code:

import javax.swing.table.DefaultTableModel;

/**
 *
 * @author 1BestCsharp
 */
public class JTable_Load_Clear_Data extends javax.swing.JFrame {

    /**
     * Creates new form JTable_Load_Clear_Data
     */
    public JTable_Load_Clear_Data() {
        initComponents();
        ShowData();
    }
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonLoad = new javax.swing.JButton();
        jButtonClear = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButtonLoad.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButtonLoad.setText("Load");
        jButtonLoad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLoadActionPerformed(evt);
            }
        });

        jButtonClear.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jButtonClear.setText("Clear");
        jButtonClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonLoad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonClear, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(jButtonLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonClear, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    public void ShowData()
    {
        
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        
        String[] cols = {"Id","First Name","Last Name","Age"};
        String[][] data = { 
                            {"1", "FN1","LN1","10"},
                            {"2", "FN1","LN1","15"},
                            {"3", "FN1","LN1","20"},
                            {"4", "FN1","LN1","25"},
                            {"5", "FN1","LN1","30"},
                            {"6", "FN1","LN1","35"},
                            {"7", "FN1","LN1","40"},
                            {"8", "FN1","LN1","45"},
                            {"9", "FN1","LN1","50"},
                            {"10", "FN1","LN1","60"}
                          };
        
        model.setDataVector(data, cols);
        
        
    }
    
    private void jButtonLoadActionPerformed(java.awt.event.ActionEvent evt) {                                            
       
        ShowData();
        
    }                                           

    private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {                                             
        jTable1.setModel(new DefaultTableModel(null,new String[]{"Id","First Name","Last Name","Age"}));
        
    }                                            

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JTable_Load_Clear_Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JTable_Load_Clear_Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JTable_Load_Clear_Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JTable_Load_Clear_Data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JTable_Load_Clear_Data().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButtonClear;
    private javax.swing.JButton jButtonLoad;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration                   
}


// OUTPUT :


Load And Remove JTable Content In Java




Java jRadioButton

How To Use RadioButton In Java Using NetBeans

java radiobutton



In this Java Tutorial we will see How To Add And Use Radio Button With Button Group 
In Java NetBeans .




Project Source Code:


import java.awt.Color;
import java.awt.Font;
import javax.swing.ButtonGroup;

/**
 *
 * @author 1BestCsharp
 */
public class Java_RadioButton extends javax.swing.JFrame {

    /**
     * Creates new form Java_RadioButton
     */
    public Java_RadioButton() {
        initComponents();
        ButtonGroup BtnGr = new ButtonGroup();
        BtnGr.add(RDBTN1);
        BtnGr.add(RDBTN2);
        BtnGr.add(RDBTN3);
        BtnGr.add(RDBTN4);
        
        RDBTN1.setSelected(true);
        RDBTN1ActionPerformed(null);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        RDBTN2 = new javax.swing.JRadioButton();
        RDBTN1 = new javax.swing.JRadioButton();
        RDBTN3 = new javax.swing.JRadioButton();
        RDBTN4 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        RDBTN2.setText("Green");
        RDBTN2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RDBTN2ActionPerformed(evt);
            }
        });

        RDBTN1.setText("Red");
        RDBTN1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RDBTN1ActionPerformed(evt);
            }
        });

        RDBTN3.setText("Blue");
        RDBTN3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RDBTN3ActionPerformed(evt);
            }
        });

        RDBTN4.setText("Orange");
        RDBTN4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RDBTN4ActionPerformed(evt);
            }
        });

        jLabel1.setText("//////////////////");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(RDBTN3)
                    .addComponent(RDBTN1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(RDBTN4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(RDBTN2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(62, 62, 62))
            .addGroup(layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(108, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RDBTN2)
                    .addComponent(RDBTN1))
                .addGap(47, 47, 47)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(RDBTN3)
                    .addComponent(RDBTN4))
                .addGap(43, 43, 43))
        );

        pack();
    }// </editor-fold>                        

    private void RDBTN1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        jLabel1.setForeground(Color.red);
        jLabel1.setFont(new Font("Tahoma",Font.BOLD,15));
    }                                      

    private void RDBTN2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
         jLabel1.setForeground(Color.GREEN);
          jLabel1.setFont(new Font("Tahoma",Font.ITALIC,20));
    }                                      

    private void RDBTN3ActionPerformed(java.awt.event.ActionEvent evt) {                                       
         jLabel1.setForeground(Color.BLUE);
          jLabel1.setFont(new Font("Tahoma",Font.BOLD,25));
    }                                      

    private void RDBTN4ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        jLabel1.setForeground(Color.ORANGE);
         jLabel1.setFont(new Font("Tahoma",Font.ITALIC,30));
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
      
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_RadioButton.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_RadioButton.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_RadioButton.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_RadioButton.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_RadioButton().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JRadioButton RDBTN1;
    private javax.swing.JRadioButton RDBTN2;
    private javax.swing.JRadioButton RDBTN3;
    private javax.swing.JRadioButton RDBTN4;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration                   

}

// OUTPUT :

using jradiobutton in java




Java Get Mouse Coordinates

How To Get Cursor Position In Java

java get mouse coordinates



In this Java Tutorial we will see How To Get Mouse Coordinates [X ; Y] In Using Java Eclipse.




Project Source Code:

package p;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class Mouse_CR extends JFrame {

private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Mouse_CR frame = new Mouse_CR();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public Mouse_CR() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 608, 448);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 592, 410);
contentPane.add(panel);
JLabel label = new JLabel(".................");
label.setFont(new Font("Tahoma", Font.BOLD, 20));
panel.add(label);
panel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
label.setText("X = "+ e.getX()+" ; Y = "+e.getY());
}
});
}
}


// OUTPUT :

java get cursor position