Tuesday, April 26, 2011

How to create pop up menu in java


When you're working on a worksheet, such as Word or Notepad and then you do right-click popup menu will appear that contains facilities Copy, Paste, and so forth.
By using the API PopupMenu, you can create your own menu. Popup menu is defined by an event trigger that is able to control the program, and refined through MouseEvent method which is used to detect the mouse.

Below are examples of program code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class PopUpMenu extends JPanel implements ActionListener{
PopupMenu popup;

public PopUpMenu(){
MenuItem mi;
popup=new PopupMenu("Edit");
mi=new MenuItem("Cut");
mi.addActionListener(this);
popup.add(mi);

mi=new MenuItem("Copy");
mi.addActionListener(this);
popup.add(mi);
add(popup);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
resize(200,200);
}
public void processMouseEvent(MouseEvent e){
if(e.isPopupTrigger()){
popup.show(e.getComponent(),e.getX(),e.getY());
}
super.processMouseEvent(e);
}
public void actionPerformed(ActionEvent e){
String command=e.getActionCommand();
if (command.equals("Cut")){
JOptionPane.showMessageDialog(null,"CUT");
}
}
public static void main(String args[]){
JFrame frame=new JFrame();

frame.getContentPane().add(new PopUpMenu(),BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
frame.setSize(300,300);
}

}


Save with filename: PopUpMenu.java

Saturday, April 23, 2011

Get Cursor Position using Visual basic

Visual Basic has a tool Spy + + is good. Spy + + has a feature that allows you to get all sorts of information, such as the Class Name, Window Handle, Window Caption, even all the style attributes and message contained in the window. This is simply done by moving the Finder Tool according dengann your own. All the secret behind that found in desktop applications can be found by using the Finder Tool. Finder Tool Information generated, can be used to helps to build applications programmers wanted.
Finder Tool on Spy + + utilizing the API function GetCursorpos and WindowFromPoint and both embedded (embedded) in a procedure library user32.dll. Here's a complete documentation about GetCursorPos.

Syntax
GetCursorPos Lib "USER32" (lpPoint as POINTAPI) as Long

Function
Returns the position coordinates (x, y) cursor on the screen.
Parameter
lpPoint: a declaration of POINTAPI structure that receives the coordinates of the position of the cursor on the screen. Before filling this parameter, first declaring Type POINTAPI be done.

Type POINTAPI
x as Long
y as Long
End Type


Sample preview program:



to download sample program, click here.

Displaying Time Systems using Java (2)

In addition to using the previous format, you also can display the time through the function Date(). You do not need to use the format, but through the functions provided by Java.
Below are examples of program code:


import java.lang.System;
import java.util.Date;

public class DateApp{
public static void main(String args[]){
Date today=new Date();

String days[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

System.out.println("Current time (lokal) :" + today.toLocaleString() );
System.out.println("Current time (Unix) :" + today.toString() );
System.out.println("Current time (GMT) :" + today.toGMTString() );

System.out.println("Date: "+ today.getDate());
System.out.println("Day: "+ days[today.getDay()]);
System.out.println("Hour: "+ today.getHours());
System.out.println("Minute: "+ today.getMinutes());
System.out.println("Second: "+ today.getSeconds());
}
}



Save with filename: DateApp.java

Displaying Time Systems using Java

One way to find out when the system is to use a format that is already provided by the Java package. You simply write the appropriate format and then call the command to display it.
But earlier, note first that the command format used to access time.



Below are examples of program code:


import java.text.*;
import java.util.*;

class FormatDate{
public static void main(String args[]){
String pattern="' \n Tahun:'";
pattern +="yyyy GG";
pattern +="'.\n Bulan : '";
pattern +="MMMMMMMMM";
pattern +="'.\n Jam :'";
pattern +="hh";
pattern +="a, zzzz";
pattern +="'.'";

SimpleDateFormat format=new SimpleDateFormat(pattern);
String formattedDate=format.format(new Date());
System.out.println(formattedDate);
}
}

save with filename: FormatDate.java


Server Database Driver for Java

The first step to connecting with the database server is called the JDBC Driver from server database that we use. Driver is a library that is used to communicate with the server database. Drivers each server database is different, so you must adjust the JDBC driver with the server database you use. The following is a list of driver names from some database server that is often used


Wednesday, April 20, 2011

Magnetic Form in Visual Basic

This program will "stick" this window to another application. It will stay on the left of the other app, and it will match its height. If the other app moves too far to the left for this window to fit, it will stick to the right side. If the other app maximizes, this one will revert to it's original size and float on top. If the other app minimizes, so will this one. Note that floating on top will work ONLY when this program is compiled and run as an EXE.


To download this sample program, click here

My Generate Effect Using Visual Basic


If you make an application with register form in it, then please try to generate the effect of this code. By using code generated effects, then the application will look more convincing, just as it has good security.




To Download this sample program,click here

Monday, April 18, 2011

Beep Sound in Java


You can give a beep on the button you created with Swing. The process works is that when the button is pressed, button will sound. This occurs through the use actionPerformed method () which will capture the event from the button through the addActionListener (),Then call beep() method
Below are examples of program code:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Beep {

Beep() {

JFrame frame1 = new JFrame("Beep");
Container c = frame1.getContentPane();


c.setLayout(new FlowLayout());


final JButton btnBeep = new JButton("Beep");
c.add(btnBeep);
frame1.setVisible(true);

frame1.pack();


btnBeep.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Toolkit.getDefaultToolkit().beep();
}
});
}
public static void main (String[] args) {
new Beep();
}
}


Save with the filename Beep.java


Saturday, April 16, 2011

Connecting Java and MS Access

To build a connection Java and the database required DriverManager. There are two important steps that need your attention. First, initialize the JDBC-ODBC driver via Class.forName(). And second, make objects in accordance with the ODBC connection used, using method DriverManager.getConnection():

Below are examples of program code:



import java.sql.*;

public class AccessCon{
public static void main(String args[]){
Connection con=null;
try{
//initialize the JDBC-ODBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//create a connection object
//username=admin , password=admin
con=DriverManager.getConnection("jdbc:odbc:AccessDB;uid='admin;pw='admin'");

if(!con.isClosed())
System.out.println("Connection Successfully.....");

}catch(Exception e){
System.out.println("Eception: " + e.getMessage());
}finally{
//close connection
try{
if(con!=null)
con.close();
}catch(SQLException e){}
}
}
}


save with filename : AccessCon.java

ODBC Configuration for Connecting Java and MS Access

To connecting java and MS. Access, we need to configure ODBC first.
Steps to configure the ODBC is as follows:

  1. Open the Control Panel> Administrative Tools> Data Sources (ODBC).



  2. On the User DSN tab, click Add, then select the driver Microsoft Access Driver (*. mdb) and click Finish.

  3. Then the display appears ODBC Microsoft Access Setup, fill in the name of the database in the Data Source Name.



  4. Click Select, then choose the database you created and click OK



  5. Klik the Advanced button to create a database login configuration, and then fill in the Login Name and password used to access the database. Then click OK

  6. Click OK in the ODBC Microsoft Access Setup dialog box and the ODBC Data Source Administrator.





From the ODBC DSN configuration, you will get results as follows:
DSN Name: AccessDB
User: Admin
Password: Admin


Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Blogger Templates