「java中的按钮代码」java按钮样式

博主:adminadmin 2023-01-12 06:09:05 708

今天给各位分享java中的按钮代码的知识,其中也会对java按钮样式进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

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代码应该怎么写

JAVA中的用法: setToolTipText 方法

JButton b = new JButton("一个按钮");

b.setToolTipText("你的提示文字");

JS中的用法: title属性

button type="button" title="你的提示文字"一个按钮/button

一个窗体,一个按钮,最简单的java代码怎写?

public class Demo extends JFrame

{

    JButton jb; //一个按钮

    public static void main(String []args){

        new Demo();

    }

    public Demo()

    {

        this.setLayout(new FlowLayout());

        jb=new JButton("按扭");

        this.add(jb);

        this.setSize(400,300);

        this.setVisible(true);

        this.setLocation(500, 200);

    }

}

java中的按钮代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java按钮样式、java中的按钮代码的信息别忘了在本站进行查找喔。