java里面怎么显示消息框啊?我知道没有比这问题更幼稚的!但我真的不懂! (30分)

  • 主题发起人 主题发起人 坏蛋是我
  • 开始时间 开始时间

坏蛋是我

Unregistered / Unconfirmed
GUEST, unregistred user!
java里面怎么显示消息框啊?
知道我怎么用的么?我用jni调用windows的API: MessageBox()!
哈哈哈!
告诉我吧!求求你了!
 
转述:
1. 所需动态连结的 dll 须置放在与执行档同一目录或windows system 目录
2. 确认 dll export 出来的函式的原型, 以目前的情况而言, 通常只拿得到 c
语言的函数原型,这时要注意 c 与 object pascal 相对应的型别, 如果需要, 在
interface 一节定义所需的资料类别
3. 在 implementation 节中宣告欲使用的函式, 语法大致如下:
procedure procname(argu...);
far;
external 'dll档名';
index n;
function funcname(argr...): datatype;
far;
external 'dll档名';
index n;
宣告时, index n 如果不写, 便是参考资料中所谓 import by name 的方式, 此
时, 由於需要从 dll 的 name table 中找出这个函式, 因此, 连结执行速度比
import by ordinal稍慢一些, 此外, 还有一种 by new name, 由於我没用过, 您可
以查一参考资料, 大意是可以 import 後改用另一个程式命名呼叫这个函式
4. 然後, 呼叫与使用就与一般的delphi 没有两样
5. 上述是直接写到呼叫dll函式的程式单元中, 此外,也可以将dll的呼叫宣告集
中到一个程式单元(import unit), delphi 内附的 wintypes, winprocs是一个例子,
您可以参考一下,同时观察一下 c 与 pascal 互相对应的资料型态
6. 除了上述的 static import 的方式, 另外有一种 dynamic import 的写法,
先宣告一个程序类型(procedural-type),程式执行时, 以 loadlibrary() api load
进来後, 再以 getprocaddress() api 取得函式的位址的方式来连结呼叫, 在object
pascal language guide p.132-133 有一个例子, 您可以参考看看
如果要举个例子, 以下是从我以前的程式节录出来的片断:
(* for cwindows 3.1 *)
unit ime31;
interface
uses
sysutils, wintypes, winprocs, dialogs;
type
(* 必要的资料型态宣告 *)
tdatentime = record
wyear, wmonth, wday: word;
whour, wmin, wsec: word;
end;

timepro = record
hwndime: hwnd;
{ ime handle }
dtinstdate: tdatentime;
{ date and time of installation }
wversion: word;
{ the version of ime }
szdescription: array[0..49] of byte;
{ description of ime module}
szname: array[0..79] of byte;
{ module name of the ime }
szoptions: array[0..29] of byte;
{ options of ime at startup}
fenable: boolean;
{ ime status;
true=activated,false=deactivated }
end;

ptimepro = ^timepro;
function setime(const simefilename: string): boolean;
far;
implementation
(* begin
呼叫 winnls.dll export 函数的宣告 *)
function impsetime(hwndime: hwnd;
lpimepro: ptimepro): boolean;far;
external 'winnls.dll';
(* end 呼叫 winnls.dll export 函数的宣告 *)
(* -------------------------------------------------- *)
(* setime(const simefilename: string): boolean;
(* ======
(* 切换到某一特定的输入法
(*
(* 传入引数:
(* simefilename: 输入法 ime 档名, 例: phon.ime;
(* 空字串: 英数输入法
(*
(* 传回值:
(* true: 切换成功
(* false: 失败
(* -------------------------------------------------- *)
function setime(const simefilename: string): boolean;
var
pimepro: ptimepro;
begin

result := false;
if maxavail < sizeof(timepro) then

begin

messagedlg('记忆体不足', mtwarning, [mbok], 0);
exit;
end
else

begin

new(pimepro);
try
if simefilename = '' then
(* 空字串, 还原到英数输入法 *)
pimepro^.szname[0] := 0
else

strpcopy(@pimepro^.szname, simefilename);
result := impsetime(0, pimepro);
(* 呼叫 impsetime *)
finally
 
我靠!晕掉!我知道了!谢谢您的光临!哈哈哈!
 
用类JOptionPane的方法:
showConfirmDialog Asks a confirming question, like yes/no/cancel.
showInputDialog Prompt for some input.
showMessageDialog Tell the user about something that has happened.
showOptionDialog The Grand Unification of the above three.
看看javado
c便知。
javax.swing
Class JOptionPane
java.lang.Object
|
+-java.awt.Component
|
+-java.awt.Container
|
+-javax.swing.JComponent
|
+-javax.swing.JOptionPane
--------------------------------------------------------------------------------
public class JOptionPane
extends JComponent
implements Accessible
JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. While the class may appear complex because of the large number of methods, almost all uses of this class are one-line calls to one of the static showXxxDialog methods shown below:
showConfirmDialog Asks a confirming question, like yes/no/cancel.
showInputDialog Prompt for some input.
showMessageDialog Tell the user about something that has happened.
showOptionDialog The Grand Unification of the above three.
Each of these methods also comes in a showInternalXXX flavor, which uses an internal frame to hold the dialog box (see JInternalFrame). Multiple convenience methods have also been defined -- overloaded versions of the basic methods that use different parameter lists.
All dialogs are modal. Each showXxxDialog method blocks the current thread until the user's interaction is complete.
icon message
input value
option buttons
The basic appearance of one of these dialog boxes is generally similar to the picture at the right, although the various look-and-feels are ultimatly responsible for the final result.

Parameters:
The parameters to these methods follow consistent patterns:
parentComponent
Defines the Component that is to be the parent of this dialog box. It is used in two ways: the Frame that contains it is used as the Frame parent for the dialog box, and its screen coordinates are used in the placement of the dialog box. In general, the dialog box is placed just below the component. This parameter may be null, in which case a default Frame is used as the parent, and the dialog will be centered on the screen (depending on the L&amp;F).
message
A descriptive message to be placed in the dialog box. In the most common usage, message is just a String or String constant. However, the type of this parameter is actually Object. It's interpretation depends on its type:
Object[]
An array of objects is interpreted as a series of messages (one per object) arranged in a vertical stack. The interpretation is recursive -- each object in the array is interpreted according to its type.
Component
The Component is displayed in the dialog.
Icon
The Icon is wrapped in a JLabel and displayed in the dialog.
others
The object is converted to a String by calling its toString method. The result is wrapped in a JLabel and displayed.
messageType
Defines the style of the message. The look&amp;feel manager may lay out the dialog differently depending on this value, and will often provide a default icon. The possible values are:
ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_MESSAGE
optionType
Defines the set of option buttons that appear at the bottom of the dialog box:
DEFAULT_OPTION
YES_NO_OPTION
YES_NO_CANCEL_OPTION
OK_CANCEL_OPTION
You aren't limited to this set of option buttons. You can provide any buttons you want using the options parameter.
options
A more detailed description of the set of option buttons that will appear at the bottom of the dialog box. The usual value for the options parameter is an array of Strings. But the parameter type is an array of Objects. A button is created for each object depending on it's type:
Component
The component is added to the button row directly.
Icon
A JButton is created with this as its label.
other
The Object is converted to a string using its toString method and the result is used to label a JButton.
icon
A decorative icon to be placed in the dialog box. A default value for this is determined by the messageType parameter.
title
The title for the dialog box.
initialValue
The default selection (input value).
When the selection is changed, setValue is invoked, which generates a PropertyChangeEvent.
If a JOptionPane has configured to all input setWantsInput the bound property JOptionPane.INPUT_VALUE_PROPERTY can also be listened to, to determine when the user has input or selected a value.
When one of the showXxxDialog methods returns an integer, the possible values are:
YES_OPTION,
NO_OPTION,
CANCEL_OPTION,
OK_OPTION, or
CLOSED_OPTION.
Examples:
Show an error dialog that displays the message, 'alert':
JOptionPane.showMessageDialog(null, "alert", "alert", ERROR_MESSAGE);

Show an internal information dialog with the message, 'information':
JOptionPane.showInternalMessageDialog(frame, INFORMATION_MESSAGE,
"information", "information");
Show an information panel with the options yes/no and message 'choose one':
JOptionPane.showConfirmDialog(null,
"choose one", "choose one", YES_NO_OPTION);
Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information:
JOptionPane.showInternalConfirmDialog(frame,
"please choose one", "information",
YES_NO_CANCEL_OPTION, INFORMATION_MESSAGE);
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue':
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
DEFAULT_OPTION, WARNING_MESSAGE,
null, options, options[0]);
Show a dialog asking the user to type in a String:
String inputValue = JOptionPane.showInputDialog("Please input a value");

Show a dialog asking the user to select a String:
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose one", "Input",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
Direct Use:
To create and use an JOptionPane directly, the standard pattern is roughly as follows:
JOptionPane pane = new JOptionPane(arguments);
pane.set.Xxxx(...);
// Configure
JDialog dialog = pane.createDialog(parentComponent, title);
dialog.show();
Object selectedValue = pane.getValue();
if(selectedValue == null)
return CLOSED_OPTION;
//If there is not an array of option buttons:
if(options == null) {
if(selectedValue instanceof Integer)
return ((Integer)selectedValue).intValue();
return CLOSED_OPTION;
}
//If there is an array of option buttons:
for(int counter = 0, maxCounter = options.length;
counter < maxCounter;
counter) {
if(options[counter].equals(selectedValue))
return counter;
}
return CLOSED_OPTION;
For the keyboard keys used by this component in the standard Look and Feel (L&amp;F) renditions, see the JOptionPane key assignments.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.
 
调用本地方法的applet,会弹出安全警告对话框吧?
那个叫人家用swing得太不负责任,为了一个messagebox,就让人家用户装swing
用Frame模拟也比swing强啊!
 
是啊,我看就用frame或者dialog来顶一下巴
 
有这么麻烦吗?还要用JNI,其实JAVA的SWING包已经提供了,而且还是跨平台跨语言的.
具体使用方式
Show an error dialog that displays the message, 'alert':
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);

Show an internal information dialog with the message, 'information':
JOptionPane.showInternalMessageDialog(frame, "information",
"information", JOptionPane.INFORMATION_MESSAGE);
Show an information panel with the options yes/no and message 'choose one':
JOptionPane.showConfirmDialog(null,
"choose one", "choose one", JOptionPane.YES_NO_OPTION);
Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information:
JOptionPane.showInternalConfirmDialog(frame,
"please choose one", "information",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue':
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
Show a dialog asking the user to type in a String:
String inputValue = JOptionPane.showInputDialog("Please input a value");

Show a dialog asking the user to select a String:
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose one", "Input",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
 
今天解决了一个大问题,高兴,结贴,散分!
 
后退
顶部