Java project code
Java project code
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UserRegistration frame = new UserRegistration();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public UserRegistration() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(450, 190, 1014, 597);
setResizable(false);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String firstName = firstname.getText();
String lastName = lastname.getText();
String emailId = email.getText();
String userName = username.getText();
String mobileNumber = mob.getText();
int len = mobileNumber.length();
String password = passwordField.getText();
try {
Connection connection =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "ANUP", "anup");
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 22));
btnNewButton.setBounds(399, 447, 259, 74);
contentPane.add(btnNewButton);
}
}
-----------------------------------------------------------------------------------
/*
*/
package com.exchange;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.InputStream;
import java.net.*;
import com.google.gson.*;
/**
* @author pakallis
*/
classRecv
public Recv(
return lhs;
return rhs;
public classConvertextendsHttpServlet {
/**
*/
HttpSession session;
resp.setContentType("text/html;charset=UTF-8");
amount = req.getParameter("amount");
curTo = req.getParameter("to");
curFrom = req.getParameter("from");
try {
String nextToken;
out.write(strto.nextToken());
nextToken = strto.nextToken();
out.println(" "+nextToken);
} catch (NumberFormatException e) {
/**
*/
@Override
processRequest(request, response);
}
/**
*/
@Override
processRequest(request, response);
/**
*/
@Override
}// </editor-fold>
}
-----------------------------------------------------------------------
package guessinggame;
* Java game “Guess a Number” that allows user to guess a random number that has
been generated.
*/
import javax.swing.*;
publicclassGuessingGame {
publicstaticvoidmain(String[] args) {
int userAnswer = 0;
int count = 1;
userAnswer = Integer.parseInt(response);
count++;
else {
---------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
if(e.getActionCommand().equals("Result"))
{
if(check())
count=count+1;
current++;
//System.out.println("correct ans="+count);
JOptionPane.showMessageDialog(this,"correct ans="+count);
System.exit(0);
}
}
void set()
{
jb[4].setSelected(true);
if(current==0)
{
l.setText("Que1: Which one among these is not a primitive datatype?");
jb[0].setText("int");jb[1].setText("Float");jb[2].setText("boolean");jb[3].setText(
"char");
}
if(current==1)
{
l.setText("Que2: Which class is available to all the class
automatically?");
jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object");jb[3].setTex
t("ActionEvent");
}
if(current==2)
{
l.setText("Que3: Which package is directly available to our class
without importing it?");
jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[3].setText("
lang");
}
if(current==3)
{
l.setText("Que4: String class is defined in which package?");
jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText(
"awt");
}
if(current==4)
{
l.setText("Que5: Which institute is best for java coaching?");
jb[0].setText("Utek");jb[1].setText("Aptech");jb[2].setText("SSS
IT");jb[3].setText("jtek");
}
if(current==5)
{
l.setText("Que6: Which one among these is not a keyword?");
jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if"
);
}
if(current==6)
{
l.setText("Que7: Which one among these is not a class? ");
jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent"
);
jb[3].setText("Button");
}
if(current==7)
{
l.setText("Que8: which one among these is not a function of Object
class?");
jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");
jb[3].setText("getDocumentBase");
}
if(current==8)
{
l.setText("Que9: which function is not present in Applet class?");
jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("d
estroy");
}
if(current==9)
{
l.setText("Que10: Which one among these is not a valid component?");
jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButtonGroup");
jb[3].setText("JTextArea");
}
l.setBounds(30,40,450,20);
for(int i=0,j=0;i<=90;i+=30,j++)
jb[j].setBounds(50,80+i,200,20);
}
boolean check()
{
if(current==0)
return(jb[1].isSelected());
if(current==1)
return(jb[2].isSelected());
if(current==2)
return(jb[3].isSelected());
if(current==3)
return(jb[0].isSelected());
if(current==4)
return(jb[2].isSelected());
if(current==5)
return(jb[2].isSelected());
if(current==6)
return(jb[1].isSelected());
if(current==7)
return(jb[3].isSelected());
if(current==8)
return(jb[1].isSelected());
if(current==9)
return(jb[2].isSelected());
return false;
}
public static void main(String s[])
{
new OnlineTest("Online Test Of Java");
}
}
------------------------------------------------------------------------
// Frame
JFrame f;
// Constructor
editor()
{
// Create a frame
f = new JFrame("editor");
try {
// Set metal look and feel
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
// Text component
t = new JTextArea();
// Create a menubar
JMenuBar mb = new JMenuBar();
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi9);
m2.add(mi4);
m2.add(mi5);
m2.add(mi6);
mc.addActionListener(this);
mb.add(m1);
mb.add(m2);
mb.add(mc);
f.setJMenuBar(mb);
f.add(t);
f.setSize(500, 500);
f.show();
}
// If a button is pressed
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("cut")) {
t.cut();
}
else if (s.equals("copy")) {
t.copy();
}
else if (s.equals("paste")) {
t.paste();
}
else if (s.equals("Save")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");
if (r == JFileChooser.APPROVE_OPTION) {
try {
// Create a file writer
FileWriter wr = new FileWriter(fi, false);
// Write
w.write(t.getText());
w.flush();
w.close();
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
// If the user cancelled the operation
else
JOptionPane.showMessageDialog(f, "the user cancelled the
operation");
}
else if (s.equals("Print")) {
try {
// print the file
t.print();
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
}
}
else if (s.equals("Open")) {
// Create an object of JFileChooser class
JFileChooser j = new JFileChooser("f:");
try {
// String
String s1 = "", sl = "";
// File reader
FileReader fr = new FileReader(fi);
// Buffered reader
BufferedReader br = new BufferedReader(fr);
// Initialize sl
sl = br.readLine();
// Main class
public static void main(String args[])
{
editor e = new editor();
}
}
--------------------------------------------------------------------
project 6: Converting Text to Speech in Java
import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
try {
// Set property as Kevin Dictionary
System.setProperty(
"freetts.voices",
"com.sun.speech.freetts.en.us"
+ ".cmu_us_kal.KevinVoiceDirectory");
// Register Engine
Central.registerEngineCentral(
"com.sun.speech.freetts"
+ ".jsapi.FreeTTSEngineCentral");
// Create a Synthesizer
Synthesizer synthesizer
= Central.createSynthesizer(
new SynthesizerModeDesc(Locale.US));
// Allocate synthesizer
synthesizer.allocate();
// Resume Synthesizer
synthesizer.resume();
catch (Exception e) {
e.printStackTrace();
}
}
}
----------------------------------------------------------------------