Skip to main content

Posts

Showing posts with the label Java ActionListener

Write a Java program to design a screen with two textbox and start button. Clicking on start button should start two threads printing 1 to 100 in two textbox.

Write a Java program to design a screen with two textbox and start button. Clicking on start button should start two threads printing 1 to 100 in two textbox. Program: import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class ThreadBox extends JApplet implements Runnable, ActionListener { TextArea ta1, ta2; Button btnStart; Thread t1, t2; public void init(){ ta1 = new TextArea(1,20); ta2 = new TextArea(1,20); btnStart = new Button("Start"); setLayout(new FlowLayout()); btnStart.addActionListener(this); add(ta1); add(ta2); add(btnStart); } public void run(){ int i; String str = Thread.currentThread().getName(); if(str.equals("First")){ for(i=1;i<=100;i++){ try{ ta1.append(" "+i) t1.sleep(500); ...

Write a Java program to display the record of Student(rollNo, name, marks) on the screen by selecting rollno from the choice component.

Write a Java program to display the record of Student(rollNo, name, marks) on the screen by selecting rollno from the choice component. Program: import java.awt.*; import java.awt.event.*; import java.sql.*; import java.io.*; public class Student extends Frame implements ActionListener { Choice rollNo; Connection con; Statement stmt; ResultSet rs; String sql; public Student() throws SQLException, ClassNotFoundException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:patientDSN"); stmt = con.createStatement(); rs.executeQuery("Select * from student"); setSize(300,200); setVisible(true); setLayout(new FlowLayout()); addWindowListener(new WClose()); rollNo.ItemListener(this); while(rs.next()){ rollNo.addItem(String.valueOf(rs.getInt(1))); } add(rollNo); } stmt.close()...

Write a Java program to accept the details of patient(pno, pname) from user and insert it into the database, display it and delete the record of entered pno from the table

Write a Java program to accept the details of patient(pno, pname) from user and insert it into the database, display it and delete the record of entered pno from the table Program: import java.io.*; import java.sql.*; import java.awt.*; import java.awt.event.*; public class Patient extends Frame implements ActionListener { Label labelPNo, labelPName; TextField textPNo, textPName; Button btnAdd, btnDelete; String sql; Statement stmt; Connection con; public Patient() throws SQLException, ClassNotFoundException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:patientDSN"); setLayout(new FlowLayout()); setSize(300,200); labelPNo = new Label("Patient No:"); labelPName = new Label("Patient Name:"); textPNo = new TextField(20); textPName = new TextField(20); btnAdd = new Button("Add"); ...