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

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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