導航:首頁 > 編程語言 > java滑鼠提示

java滑鼠提示

發布時間:2024-06-09 18:58:34

java能不能做當滑鼠移動到按鈕或文本框上時顯示提示信息

你說的是指.setToolTipText("")方法吧,聲明一下,此方法適用於任何版本的SE

代碼如下:

importjava.awt.*;
importjavax.swing.*;
//載入程序

publicclassTestextendsJFrame{
//繼承類

Test(){
//構造無參方法
MyFrame.(true);
//美觀布局
this.setUndecorated(true);
//清楚原有窗體格式
this.getRootPane().setWindowDecorationStyle(JRootPane.ERROR_DIALOG);
//更換為消息窗格式(沒有最大最小化按鈕)
this.setTitle("這是一個標題");
//為窗體添加標題
this.setSize(300,140);
//設置窗體大小
this.setResizable(false);
//設置窗體大小不可變
this.setLocation(650,250);
//設置窗體位置

JPanelPanel=newJPanel();
//添加一個容器

JLabelLabel=newJLabel("這是一個標簽");
//添加一個內容為「這是一個標簽」的標簽
Label.setFont(newFont("微軟雅黑",Font.BOLD,20));
//設置標簽字體、粗體、字型大小
Label.setForeground(Color.red);
//設置文字顏色
Label.setToolTipText("這是一個注釋");
//為標簽添加一串注釋
Panel.add(Label);
//向容器內添加此標簽

JButtonButton=newJButton("退出");
//添加一個內容為「退出」的按鈕
Button.setFont(newFont("微軟雅黑",Font.BOLD,20));
//設置按鈕字體、粗體、字型大小
Button.setToolTipText("這是一個注釋");
//為按鈕添加一串注釋
Button.addActionListener(newActionListener(){
//為按鈕添加一個監視器
@Override
publicvoidactionPerformed(ActionEvente){
System.exit(0);
//設置按鈕按下的事件為關閉程序
}
});
Panel.add(Button);
//向容器內添加此按鈕

this.add(Panel);
//向窗體內添加此容器
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//設置窗體的關閉按鈕為無動作
this.setVisible(true);
//設置窗體可見
}

}
希望可以解決答主疑問

Ⅱ java中JTextfield怎樣使它有提示內容,就是文本框默認有內容,滑鼠點進去內容消失這樣的

packagecom;

importjava.awt.FlowLayout;
importjava.awt.event.FocusAdapter;
importjava.awt.event.FocusEvent;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JTextField;

publicclassKyoextendsJFrame
{
publicKyo()
{
(100,100);
setLayout(newFlowLayout());
finalJTextFieldtextField=newJTextField(11);
textField.addFocusListener(newFocusAdapter()
{
@Override
publicvoidfocusGained(FocusEvente)
{
textField.setText("");
}
@Override
publicvoidfocusLost(FocusEvente)
{
textField.setText("輸入內容");
}
});
add(textField);
add(newJButton("dd"));
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
publicstaticvoidmain(String[]args)
{
newKyo();
}
}

Ⅲ java涓鎬庢牱鍒朵綔灝嗛紶鏍囨斁緗鍦ㄦ爣棰樹笂鍙浠ョ浉搴旀樉紺轟俊鎮錛屽彧鏄灝嗛紶鏍囨斁緗鍦ㄤ笂闈涓嶉渶瑕佺偣鍑誨氨鍙浠ユ樉紺轟俊鎮

鐢╦s錛岃劇疆onmouseover浜嬩歡鍗沖湪浣犵殑鏍囬樻爣絳鵑噷鍔犱笂onmouseover="alert('鍐欎綘鎯蟲樉紺虹殑鍐呭癸紒')"灝眔k浜嗕笉鐢ㄧ偣鍑匯傝繖涓猨s濂藉ソ鐪嬬湅榪欎簺鍔熻兘緇忓父鐢錛屼粬涓嶄粎鏈夋樉紺烘枃鏈鐨勫姛鑳藉浘鐗囧晩鍑芥暟鍟婇兘鍙浠ヨ皟鐢錛屽氱湅鐪

Ⅳ 用java在文本框實現滑鼠點擊事件,一點文本框直接跳出新對話框

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class Exec1 extends JFrame {

public Exec1() {
JTextField txt = new JTextField();
txt.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
new A().setVisible(true);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
});
add(txt);
setSize(100, 65);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String [] args) {
new Exec1().setVisible(true);
}
}

class A extends JFrame {
public A() {
setSize(400, 400);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}

閱讀全文

與java滑鼠提示相關的資料

熱點內容
windows編程如何讀取文件大小 瀏覽:947
2017程序員工資統計 瀏覽:153
ps2021暫存檔文件手動清理 瀏覽:459
fdt表中的長文件名 瀏覽:508
mysql管理員默認密碼 瀏覽:359
越獄ios8直接刪系統文件 瀏覽:490
文件櫃的傾斜度是多少 瀏覽:115
蘋果耳機切換不了 瀏覽:968
有什麼小說網站可以看所有小說 瀏覽:661
蘋果雲盤文件怎麼存在 瀏覽:466
紅米手機裡面的txt文件 瀏覽:360
華為pad攝像頭在哪個文件夾 瀏覽:147
手機版編程貓如何復制角色 瀏覽:599
動漫圖片的文件格式 瀏覽:560
黑衣緊身美女跳小蘋果 瀏覽:670
無法收縮資料庫 瀏覽:216
java中獲取二維數組的長度 瀏覽:510
手機裡面的數據線怎麼接 瀏覽:491
微信轉帳是紅包嗎 瀏覽:748
如何學會函數編程 瀏覽:985

友情鏈接