Friday, February 27, 2015
Thursday, February 26, 2015
JAVA awt Event Handling:KeyEvent Example
JAVA awt Event Handling:KeyEvent Example
KeyEvent
*********************************************************
import java.awt.event.*;import java.awt.*;
class KeyListenerImpl implements KeyListener
{
public void keyPressed(KeyEvent ke)
{
System.out.println("Key Pressed.."+ke.getKeyChar());
}
public void keyTyped(KeyEvent ke)
{
System.out.println("Key Typed.."+ke.getKeyChar());
}
public void keyReleased(KeyEvent ke)
{
System.out.println("Key Released.."+ke.getKeyChar());
}
}
class MyFrame extends Frame
{
MyFrame()
{
this.setVisible(true);
this.setTitle("Key Event Example");
this.setBackground(Color.yellow);
this.setSize(500,500);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
this.addKeyListener(new KeyListenerImpl());
}
}
class KeyEventEx
{
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}
Labels:
awt,
awt program,
core java,
event handling,
java,
java.awt.event,
Mouse,
swing
JAVA awt Event Handling:Mouse Event Example 2 MouseAdapter
JAVA awt Event Handling:Mouse Event Example 2 MouseAdapter
MouseAdapter
******************************************************************
import java.awt.event.*;
import java.awt.*;
class MyFrame extends Frame
{
Label xText = new Label();
Label yText = new Label();
MyFrame()
{
this.setVisible(true);
this.setTitle("Key Event Example");
this.setBackground(Color.yellow);
this.setSize(500,500);
this.setLayout(new FlowLayout());
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
this.add(yText);
this.add(xText);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
xText.setText("x="+me.getX());
yText.setText("y="+me.getY());
}
});
this.setSize(500,500);
}
}
class MouseEventEx2
{
public static void main(String[] args)
{
MyFrame mf = new MyFrame();
}
}
JAVA awt Event Handling:Mouse Event Example
Event Handling:
MouseEvent Example:
------------------------------
This program is the example of MouseEvent .*************************************************
import java.awt.event.*;
import java.awt.*;
class MouseListenerImpl implements MouseListener
{
public void mouseClicked(MouseEvent me)
{
System.out.println("Mouse Clicked.(x="+me.getX()+",y="+me.getY()+")");
//MyFrame.print(me.getX(),me.getY());
}
public void mouseReleased(MouseEvent me)
{
System.out.println("Mouse Released.(x="+me.getX()+",y="+me.getY()+")");
}
public void mousePressed(MouseEvent me)
{
System.out.println("Mouse Pressed.(x="+me.getX()+",y="+me.getY()+")");
}
public void mouseEntered(MouseEvent me)
{
System.out.println("Mouse Entered.(x="+me.getX()+",y="+me.getY()+")");
}
public void mouseExited(MouseEvent me)
{
System.out.println("Mouse Exited.(x="+me.getX()+",y="+me.getY()+")");
}
}
class MyFrame1
{
public static class MyFrame extends Frame
{
Panel p =new Panel();
Label x = new Label("X:");
Label y = new Label("Y:");
static Label xText = new Label();
static Label yText = new Label();
MyFrame()
{
this.setVisible(true);
this.setTitle("Key Event Example");
this.setBackground(Color.yellow);
this.setSize(500,500);
this.setLocationRelativeTo(null);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
this.addMouseListener(new MouseListenerImpl());
this.add(p);
p.setLayout(new GridLayout(4,2));
// p.setBackground(Color.gray);
p.add(x);
p.add(y);
p.add(xText);
p.add(yText);
}
public static void print(int x,int y)
{
String xString=x+"";
String yString=y+"";
xText.setText(xString);
xText.setText(yString);
// this.setSize(500,500);
}
}
MyFrame mf = new MyFrame();
}
class MouseEventEx
{
public static void main(String[] args)
{
MyFrame1 mf = new MyFrame1();
}
}
Screen Shot:
---------------
Labels:
awt,
awt program,
core java,
Event,
event handling,
java.awt.event,
Mouse,
swing
Wednesday, February 25, 2015
JDBC:Make a Connection between Java Program and ORACLE Database Using Type-1 driver in Window 7
Steps to create a connection between Java Program and Oracle Database:-
***********************************************************
Step1:Create a DSN name
--> Control Panel
--> System and Security
--> Administrative Tools
--> ODBC data Source
--> select System DNS tab
--> Click on Add Button
--> Scroll Down and Select Microsoft ODBC for Oracle
--> click Finish Button
--> Microsoft ODBC for Oracle Setup will display
--> Give Data Source Name
--> and press OK
--> OK
--> Completed
************************************************************
Step2:Write a JDBC program
-> Open an Editor(notepad or EditPlus or NotePad++)
--> Write Code as written below
------------------------------------------------------------------------------------------------
import java.sql.*;
public class FirstJdbcProgram
{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Load and Register the Driver
Connection con = DriverManager.getConnection("jdbc:odbc:ach","system","india");//Create Connection
if(con==null){
//DriverManager.getConnection() return null when DNS not exist or Wrong Database username and Password
System.out.println("Connection not Created");
}else{
System.out.println("Connection Created");
}
con.close();
}
}
************************************************************
*Note:
----------
1.While Writing "Class.forName "----C and N is Capital
"JdbcOdbcDriver"---J,O,and D is Capital
2.If you are facing difficulties while preparing DSN name in Windows8 or later version OS then
then try other Type of Driver Check Other post for Other type of Driver
Youtube Link:
http://youtu.be/Blfugth1Xeo
***********************************************************
Step1:Create a DSN name
--> Control Panel
--> System and Security
--> Administrative Tools
--> ODBC data Source
--> select System DNS tab
--> Click on Add Button
--> Scroll Down and Select Microsoft ODBC for Oracle
--> click Finish Button
--> Microsoft ODBC for Oracle Setup will display
--> Give Data Source Name
--> and press OK
--> OK
--> Completed
************************************************************
Step2:Write a JDBC program
-> Open an Editor(notepad or EditPlus or NotePad++)
--> Write Code as written below
------------------------------------------------------------------------------------------------
import java.sql.*;
public class FirstJdbcProgram
{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Load and Register the Driver
Connection con = DriverManager.getConnection("jdbc:odbc:ach","system","india");//Create Connection
if(con==null){
//DriverManager.getConnection() return null when DNS not exist or Wrong Database username and Password
System.out.println("Connection not Created");
}else{
System.out.println("Connection Created");
}
con.close();
}
}
************************************************************
*Note:
----------
1.While Writing "Class.forName "----C and N is Capital
"JdbcOdbcDriver"---J,O,and D is Capital
2.If you are facing difficulties while preparing DSN name in Windows8 or later version OS then
then try other Type of Driver Check Other post for Other type of Driver
Youtube Link:
http://youtu.be/Blfugth1Xeo
Labels:
core java,
driver,
java,
jdbc connection,
jdbcprogram,
oci,
simple
Subscribe to:
Posts (Atom)