導航:首頁 > 編程語言 > java按鈕代碼

java按鈕代碼

發布時間:2022-06-10 13:22:26

java刷新按鈕的源代碼

這好辦
需要一個標志變數
例:必須是成員變數
靜態的
static
int
flag
=
1;
下面是當刷新按鈕事件出發時,判斷flag的值
if(flag
==
1){
//執行按鈕1的操作;
flag=2;
}else
if(flag
==
2){
//執行按鈕2的操作;
flag=3;
}else
if(flag
==
3){
//執行按鈕3的操作;
flag=4;
}else
if(flag
==
4){
//執行按鈕4的操作;
flag=1;//設置為1,就可以循環刷新了
}

㈡ 那個,用java代碼怎麼寫一個按鈕事件

Button b = new Button();
b.setLabel("點擊");
b.addMouseListener(new MouseListener(){
重寫介面的方法
});

㈢ 用java寫按鈕和窗體的代碼是什麼

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class TestVerify {
public static void main(String[] args) {
new LoginFrame();
}

}

class LoginFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;

private JLabel nameLab;
private JLabel pwdLab;
private JButton confirmBtn;
private JTextField jtf_name;
private JPasswordField jtf_pwd;
private JButton resetBtn;

public LoginFrame() {
init();
}

public void init() {
setTitle("Login..");
setSize(260, 200);
setResizable(false);
setUndecorated(false);
//setAlwaysOnTop(true);

Toolkit tk = Toolkit.getDefaultToolkit();
setLocation((tk.getScreenSize().width - this.getWidth())/2,
(tk.getScreenSize().height - this.getHeight())/2);

//this.setLocationRelativeTo(null); //設置屏幕居中顯示方法

//tk.setLockingKeyState(java.awt.event.KeyEvent.VK_NUM_LOCK, false); //設定num_lock鍵初始狀態為鎖定(鍵盤指示燈不亮)

nameLab = new JLabel("用戶名:");
jtf_name = new JTextField(12);
pwdLab = new JLabel("密碼:");
jtf_pwd = new JPasswordField(12);
confirmBtn = new JButton("確定");
resetBtn = new JButton("重置");

confirmBtn.addActionListener(this);
resetBtn.addActionListener(this);

JPanel jp_out = new JPanel();
JPanel jp_up = new JPanel();
JPanel jp_cen = new JPanel();
JPanel jp_down = new JPanel();

jp_up.setBounds(20, 20,200,30);
jp_up.add(nameLab);
jp_up.add(jtf_name);

jp_cen.setBounds(27, 50,200,30);;
jp_cen.add(pwdLab);
jp_cen.add(jtf_pwd);

jp_down.setBounds(30, 90,200,50);;
jp_down.add(confirmBtn);
jp_down.add(resetBtn);

jp_out.setLayout(null);
jp_out.add(jp_up,BorderLayout.NORTH);
jp_out.add(jp_cen,BorderLayout.CENTER);
jp_out.add(jp_down,BorderLayout.SOUTH);

add(jp_out);

setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand() == "確定") {
//System.out.println( JOptionPane.PLAIN_MESSAGE );
JOptionPane.showMessageDialog(this, "確定", "登陸提示。。。", JOptionPane.INFORMATION_MESSAGE);
}
if(e.getActionCommand() == "重置") {
jtf_name.setText("");
jtf_pwd.setText("");
}

}

/*public boolean verifyPassword(String name, String password) {

return false;
}*/

}

㈣ java中做一個按鈕,點擊按鈕後畫一個矩形的代碼怎麼寫

兄弟幫你寫了一個:

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

public class Print {
public static void main(String[] args) {
new Te();
}
}

class Te extends Frame implements ActionListener {

Color cc = Color.red;
int x = -20, y = -50;
Random r = new Random();

public Te() {

this.setLayout(null);
Button b = new Button("畫圓");
this.add(b);
b.setBounds(30,30,50,50);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter () {

@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}

});
this.setBounds(200,200,500,400);
this.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
this.cc = Color.red;
this.x = r.nextInt(400);
do {
int x1 = r.nextInt(300);
this.y = x1;
} while (this.y < 50);

this.repaint();
}

@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(cc);
g.drawRect(x,y,50,50);
g.setColor(c);
}
}

㈤ java編程中按鈕位置的代碼

setLayoutManager(new BorderLayout());
然後像這樣依次添加按鈕:(具體添加到面板還是窗體由你自己決定了)
add(b1,BorderLayout.south)
add(b2,BorderLayout.north)
add(b3,BorderLayout.east)
add(b4,BorderLayout.west)
用了borderlayout之後,setbounds方法是無效的,可以刪除這些冗餘代碼

㈥ java 按鈕問題 用什麼代碼實現

JTabbedPane tabs = new JTabbedPane();
JPanel tab1= new JPanel();
tab1.setLayout(null);
tabs.add("主題",tab1);

JPanel tab2= new JPanel();
tab2.setLayout(null);
tabs.add("桌面",tab2);

JPanel tab3= new JPanel();
tab3.setLayout(null);
tabs.add("屏幕保護程序",tab3);

㈦ 在java中使用什麼代碼,可以使按鈕具有打開目標文件夾的功能

打開文件

//打開工具的路徑及名字

String toolsPath = "C:/WINDOWS/system32/notepad.exe ";

//被打開文件的路徑及名字

String fileName = "test.txt";

try {

Runtime.getRuntime().exec(toolsPath+fileName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

打開文件夾

try {

String[] cmd = new String[5];

String url = "C:/input";

cmd[0] = "cmd";

cmd[1] = "/c";

cmd[2] = "start";

cmd[3] = " ";

cmd[4] = url;

Runtime.getRuntime().exec(cmd);

} catch (IOException e) {

e.printStackTrace();

}

或者

Runtime.getRuntime().exec("cmd /c start C:/input");

希望採納

㈧ 一個窗體,一個按鈕,最簡單的java代碼怎寫

publicclassDemoextendsJFrame
{
JButtonjb;//一個按鈕
publicstaticvoidmain(String[]args){
newDemo();
}
publicDemo()
{
this.setLayout(newFlowLayout());
jb=newJButton("按扭");
this.add(jb);
this.setSize(400,300);
this.setVisible(true);
this.setLocation(500,200);
}
}

㈨ JAVA的按紐代碼的一點問題(BottonTest)如下

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonTest{
public static void main(String[] args){
ButtonFrame frame=new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ButtonFrame extends JFrame{
public ButtonFrame(){
setTitle("ButtonTest");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
ButtonPanel panel=new ButtonPanel();
add(panel);
}
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=200;
}
class ButtonPanel extends JPanel{
public ButtonPanel(){
JButton yellowButton=new JButton("Yellow");
JButton blueButton=new JButton("Blue");
JButton redButton=new JButton("Red");

add(yellowButton);
add(blueButton);
add(redButton);

ColorAction yellowAction=new ColorAction(Color.YELLOW,this);
ColorAction blueAction=new ColorAction(Color.BLUE,this);
ColorAction redAction=new ColorAction(Color.RED,this);

yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
}

class ColorAction implements ActionListener{
Color c;
ButtonPanel panel;
public ColorAction(Color c,ButtonPanel panel){
this.c=c;
this.panel=panel;
}

public void actionPerformed(ActionEvent event){
panel.setBackground(c);
}

}

㈩ Java中按鈕事件代碼

加入在frame中的按鈕名為sure
Button sure=new Button("確定");
sure.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
frame1.setVisible(false);
Frame frame2=new Frame();
frame2.setVisible(true);

}
});

閱讀全文

與java按鈕代碼相關的資料

熱點內容
php數組傳遞給js 瀏覽:639
在世紀的轉折點上pdf 瀏覽:856
變頻製冷壓縮機性能實驗 瀏覽:574
印刷哪個app好 瀏覽:366
安卓手機如何查看連接過的wifi密碼 瀏覽:460
chrpythonord 瀏覽:353
android切片 瀏覽:230
前端js調用php 瀏覽:590
文件夾res是什麼 瀏覽:488
linuxput命令 瀏覽:931
智能仿生演算法模擬退火 瀏覽:903
汽車辦解壓能代辦嗎 瀏覽:12
美林程序員 瀏覽:841
安卓如何開網路 瀏覽:730
宿來app什麼時候上線 瀏覽:764
成都python培訓機構好不好 瀏覽:421
mysql查看配置命令 瀏覽:597
v8編譯cmake 瀏覽:965
app品牌起步階段需要什麼營銷 瀏覽:358
壓縮機製冷劑溫度 瀏覽:930