導航:首頁 > 編程語言 > 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滑鼠提示相關的資料

熱點內容
nsh是什麼文件 瀏覽:119
手機QQ怎麼不能傳文件 瀏覽:450
u盤復制文件的速度取決於什麼 瀏覽:659
iphone4下拉通知欄 瀏覽:427
javasocket接收數據包 瀏覽:137
如何給類數據成員變數設置默認值 瀏覽:885
密集app怎麼推廣 瀏覽:866
WP7屏幕保護程序 瀏覽:568
win10雙硬碟老藍屏 瀏覽:986
怎麼設置網站描述 瀏覽:274
微信壓縮包可以發送多大文件 瀏覽:916
u盤打開很卡無法復制裡面文件 瀏覽:143
app怎麼刪不掉 瀏覽:324
農村工作一號文件圖片 瀏覽:598
錘子手機怎麼樣升級 瀏覽:706
微信朋友圈哲理說說 瀏覽:649
jscss模板 瀏覽:472
圖片文件夾里多了一個 瀏覽:305
索尼a7r2配置文件 瀏覽:706
獲取jsp中a中text 瀏覽:396

友情鏈接