Skip to main content

Posts

Showing posts with the label AWT Frame

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 accept the details of employee(eno, ename, salary) using AWT and insert into database

Write a Java program to accept the details of employee(eno, ename, salary) using AWT and insert into database. Program: import java.awt.*; import java.awt.event.*; import java.io.*; import java.sql.*; public class Employee extends Frame implements ActionListener { Label labelEno, labelEname, labelSalary; TextField textEno, textEname, textSalary; Button btnAdd; String sqlQuery; Statement s; Connection dbConnection; public Employee() throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); dbConnection = DriverManager.getConnection("jdbc.odbc:EmployeeDSN"); setLayout(new FlowLayout()); setSize(300,300); labelEno = new Label("Employee No:"); labelEname = new Label("Employee Name:"); labelSalary = new Label(Employee Salary:); textEno = new TextField(20); textEname = new TextField(20); textSalary = new TextField(20); btnAdd = new Button("Add"); btnAdd.addAction...