Posts

Showing posts from April, 2021

Create JRadioButtons ActionListener in java

Image
How to Create JRadioButtons ActionListener in java. I Have two Calsses Main.Java and other Class MyFrame My Frame Extends JFrame it behaves it’s like a JFrame it also Implements ActionListener and Constructor. So going to create 4 JRadioButtons .Button names (window xp, windows 7, windows 8.1, windows 10). So we can actually limit the choice selection only one item. Create now ButtonGroup and we need add this RadioButton to this Group. We can use are ActionPerformed method to detect which Button was selected so with in are ActionPerformed method we can place as Simple if Statement. package javaFxProject; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JRadioButton; public class MyFrame extends JFrame implements ActionListener { JRadioButton winxp; JRadioButton win7; JRadioButton win8; JRadioButton win10; ...

How to Create JTextField Validation in java swing.

Image
 How to Create JTextField Validation in java swing JTextField  can allow  numbers ,  characters , and  special  characters . Validating user input that is typed into a  JTextField  can be difficult, especially if the input string must be converted to a numeric value such as an int. package javaGuiProject; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class TextValidation extends JFrame{ JTextField text; JLabel label; JPanel p; TextValidation(){ text=new JTextField(15); label=new JLabel("Enter number:"); p=new JPanel(); p.add(label); p.add(text); text.addKeyListener(new KeyAdapter(){             public void keyPressed(KeyEvent e){                 char ch = e.getKeyChar();     ...

Creating Chat Frame in Java Swing.

Image
 Creating Chat Frame in Java Swing. package javaGuiProject; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class ChatFrameExample { public static void main(String [] args) { //Create the Frame JFrame frame = new JFrame("Hello"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,600); //Creating the MenuBar and Adding Components JMenuBar menubar = new JMenuBar(); JMenu menu1 = new JMenu("File"); JMenu menu2 = new JMenu("Help"); menubar.add(menu1); menubar.add(menu2); JMenuItem mItem1 = new JMenuItem("Open"); JMenuItem mItem2 = new JMenuItem("Save As"); menu1.add(mItem1); menu1.add(mItem2); //Creating the panel...