Posts

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...

Java Swing How to - Create Submenu on the Main menu

Image
  Java Swing How to - Create Submenu on the Main menu Menus are unique in that, by convention, they aren't placed with the other components in the UI. Instead, a menu usually appears either in a  menu bar  or as a  popup menu . A menu bar contains one or more menus and has a customary, platform-dependent location — usually along the top of a window. A popup menu is a menu that is invisible until the user makes a platform-specific mouse action, such as pressing the right mouse button, over a popup-enabled component. The popup menu then appears under the cursor. import javax.swing.*; import java.awt.event.KeyEvent; public class SubMenuExample { public static void main( final String args[]) { JFrame frame = new JFrame( "MenuSample Example" ); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu( "File" ); fileMenu.setMnemon...

Check Box With Event Listener in java Swing

Image
CheckBox with EventListener in Java Swing For CheckBox the more Common usage should be Combining is with event listener with the event listener, the checkBox can Act Different Action.. package JavaSwing; import javax.swing.*; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class CheckBoxWithEventListener { // Create Differnt CheBox public static JCheckBox cbox1 = new JCheckBox( "Name 1" ); public static JCheckBox cbox2 = new JCheckBox( "Name 2" ); public static JCheckBox cbox3 = new JCheckBox( "Name 3" ); public static JCheckBox cbox4 = new JCheckBox( "Name 4" ); public static void main(String [] args) { //Create and set up a Frame window JFrame. setDefaultLookAndFeelDecorated ( true ); JFrame frame = new JFrame( "CheckBoxWithEventLisetner" ); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ); //Define the panel to hol...