而你说的 这种效果只能 用 无边框的 pincturebox代替, 并设置 MouseMove 时间 和窗体的 MouseMove 事件
在 pic的事件中设置暗图片, 当鼠标移出pic进入窗体在窗体的时间里设置 pic为亮图片, 图片在ImageList里存放
import java.awt.FlowLayoutimport java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.*
public class MyFrame extends JFrame {
private MyFrame instance = this
/**
* @param args
*/
public static void main(String[] args) {
new MyFrame()
}
public MyFrame() {
this.setLayout(new FlowLayout())
JButton b = new JButton("close")
this.setSize(200,200)
this.add(b)
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
instance.dispose()
}
})
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE)
this.setVisible(true)
}
}
100分呀。用JDK的SWING写的,绝对不带SWT。分呀分呀。
c语言制作UI界面需要相关的UI库
如windows *** 作系统本身就提供了UI的接口
一个简单的示例代码如下
#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM)
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR line,int cmd)
{
static TCHAR AppName[]=TEXT("99")
HWND hwnd
MSG msg
WNDCLASS wndclass
wndclass.style=CS_HREDRAW|CS_VREDRAW
wndclass.lpfnWndProc=WndProc
wndclass.cbClsExtra=0
wndclass.cbWndExtra=0
wndclass.hInstance=hinstance
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION)
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW)
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH)
wndclass.lpszMenuName=NULL
wndclass.lpszClassName=AppName
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows NT!"),AppName,MB_ICONERROR)
return 0
}
hwnd=CreateWindow(AppName,TEXT("九九乘法口诀表"),\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
NULL,\
NULL,\
hinstance,\
NULL)
ShowWindow(hwnd,cmd)
UpdateWindow(hwnd)
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg)
DispatchMessage(&msg)
}
return msg.wParam
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
HDC hdc
PAINTSTRUCT ps
RECT rect
static x,y
int i,j
int len
TCHAR buf[50]
TEXTMETRIC tm
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd)
GetTextMetrics(hdc,&tm)
x=tm.tmAveCharWidth
y=tm.tmHeight+tm.tmExternalLeading
ReleaseDC(hwnd,hdc)
//MessageBox(NULL,TEXT("Create Successed!"),TEXT("Successed"),MB_OK)
//PlaySound(TEXT("hello.wav"),NULL,SND_FILENAME|SND_ASYNC)
return 0
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps)
GetClientRect(hwnd,&rect)
//DrawText(hdc,TEXT("Hello World!"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER)
//TextOut(hdc,rect.right/2-(strlen("Hello World!")/2)*x,rect.bottom/2-y/2,TEXT("Hello World!"),12)
for(i=1i!=10++i)
{
for(j=1j!=i+1++j)
{
len=wsprintf(buf,TEXT("%dx%d=%-4d"),j,i,i*j)
TextOut(hdc,j*len*x,i*y,buf,len)
}
}
EndPaint(hwnd,&ps)
return 0
case WM_DESTROY:
PostQuitMessage(0)
return 0
}
return DefWindowProc(hwnd,message,wparam,lparam)
}
上面是一个打印windows下拥有窗口界面的九九乘法口诀表的c语言程序代码
同样的c语言也会有其它的UI库
比如Gtk,Gtk是可移植的UI库
可以使用它在Linux、windows包括mac等等 *** 作系统上做ui程序设计
一个简单的示例代码如下
#include <gtk/gtk.h>int main(int argc,char **argv)
{
GtkWidget *win
GtkWidget *label
int i,j
GString *str
gtk_init(&argc,&argv)
win=gtk_window_new(GTK_WINDOW_TOPLEVEL)
gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER)
g_signal_connect(G_OBJECT(win),"delete-event",G_CALLBACK(gtk_main_quit),NULL)
str=g_string_new(NULL)
for(i=1i <= 9++i)
{
for(j=1j != i+1++j)
g_string_append_printf(str,"%dx%d=%-4d",j,i,i*j)
g_string_append(str,"\n")
}
label=gtk_label_new(str->str)
gtk_container_add(GTK_CONTAINER(win),label)
gtk_widget_show_all(win)
gtk_main()
g_string_free(str,TRUE)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)