Skip to main content

Posts

Recent posts

) Create the following GUI screen using appropriate layout managers. Accept the name, class , hobbies of the user and apply the changes and display the selected options in a text box.

  import javax.swing.*; import java.awt.*; import java.awt.event.*; class Swing2 extends JFrame implements ActionListener {     JLabel l1 , l2 , l3 ;         JButton b ;         JRadioButton r1 , r2 , r3 ;         JCheckBox c1 , c2 , c3 ;         JTextField t1 , t2 ;         ButtonGroup b1 ;         JPanel p1 , p2 ;     static int cnt ;         private StringBuffer s1 = new StringBuffer ();                 Swing2 ()         {                             b1= new ButtonGroup ();                 p1= new JPanel ();                 p2= new JPanel ();               ...

Design a screen to handle the Mouse Events such as MOUSE_MOVED and MOUSE_CLICK and display the position of the Mouse_Click in a TextField.

  import java . awt .*; import java . awt . event .*; class MyFrame extends Frame {       TextField t , t1 ;       Label l , l1 ;       int x , y ;       Panel p ;       MyFrame ( String title )       {             super ( title );             setLayout ( new FlowLayout ());             p = new Panel ();             p . setLayout ( new GridLayout ( 2 , 2 , 5 , 5 ));             t = new TextField ( 20 );             l = new Label ( "Co-ordinates of clicking" );             l1 = new Label ( "Co-ordinates of movement" );             t1 = new TextField ( 20 );             p . add ( l );         ...

Write a java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -, *, % operations. Add a text field to display the result.

  import java . awt .*; import java . awt . event .*; import javax . swing .*; class calculator extends JFrame implements ActionListener {       static JFrame f ;       static JTextField l ;       String s0 , s1 , s2 ;       calculator ()       {             s0 = s1 = s2 = "" ;       }       public static void main ( String args [])       {             f = new JFrame ( "Calculator" );           /*try            {                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());            }            catch(Exception e)            {               ...

Define a class MyDate (day, month, year) with methods to accept and display a MyDate object. Accept date as dd, mm, yyyy. Throw user defined exception “InvalidDateException” if the date is invalid. Examples of invalid dates : 03 15 2019, 31 6 2000, 29 2 2021

  import java . io .*; import java . util .*; class InvalidDateException extends Exception {       InvalidDateException ()       {               System . out . println ( "Invalid Date" );       } } class MyDate {       int day , mon , yr ;       void accept ( int d , int m , int y )       {             day = d ;             mon = m ;             yr = y ;       }       void display ()       {             System . out . println ( "Date is valid : " + day + "/" + mon + "/" + yr );       } } class Date {       public static void main ( String args []) throws Exception       {             Scanner sc = new Sca...

Write a program to read book information (bookid, bookname, bookprice, bookqty) in file “book.dat”. Write a menu driven program to perform the following operations using Random access file: i. Search for a specific book by name. ii. Display all book and total cost

  import java . io .*; import java . util .*; class Book {       String name , id ;       int qty ;       double price , total ;       Book ( String i , String n , String p , String q )      {               name = n ;               id = i ;               qty = Integer . parseInt ( q );               price = Double . parseDouble ( p );               total = qty * price ;      }       public String toString ()      {               System . out . println ( "name\t id\t qty\t price\t total" );               String s = name + "\t" + id + "\t" + qty + "\t" + price + "\t" + total ;           ...