资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java好看按钮样式代码 java按钮实现功能

怎么用java编写一个按钮界面

新建一个窗口,然后实现一个关闭按钮”窗口的功能

10年积累的成都网站设计、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有沾化免费网站建设让你可以放心的选择与我们合作。

import java.awt.*;

import java.awt.event.*;

public class TestWindowEvent {

public static void main (String[] args) {

new Frame88 ("WindowAdapter");

}

}

class Frame88 extends Frame {

Frame88 (String s) {

super(s);

setBounds (300,300,200,70);

setLayout (null);

setVisible (true);

addWindowListener (new WindowAdapter() {

public void windowClosing(WindowEvent e) {

setVisible (false);

System.exit(0);

}

}  );

}

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怎么添加一个按钮?

你就这态度???((偷笑),不想站在巨人的肩膀上了吗,人活一世,装X二字)

import javax.swing.JButton;

import javax.swing.JFrame;

public class c {

public static void main(String[] args) {

// 你懂的

JFrame jf = new JFrame();

// 你懂的

jf.setSize(300, 400);

// JFrame做为一个画板,他里面可以有控件,有控件就有控件布局的样式,样式为null可以理解为自由布局

jf.setLayout(null);

// JFrame的setVisible的默认值为false,值的意义是是否显示.

jf.setVisible(true);

// 按钮

JButton jb = new JButton("按钮");

// 添加按钮

jf.add(jb);

// 因为上面的布局样式,他设置了x50y80坐标和长100宽30

jb.setBounds(50, 80, 100, 30);

}

}

java图形化界面中如果我要设置四个按钮,然后摁每个按钮可以切换不同的图片,谁能帮我做一下代码给我参考

参考代码,

注意图片的路径,拿不准的话,就使用绝对路径吧

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

//我的图片路径是 src\\images\\1.gif  .有四张 从1.jpg~~4.jpg

public class ImageDemo extends JFrame {

JLabel jl;

JPanel jp;

public ImageDemo() {

jp = new JPanel();

int i;

for (i = 0; i  4; i++) {

if(i ==0){//初始化的时候,默认显示的图片

jl = new JLabel(new ImageIcon("src\\images\\"+1+".gif"));

}

//按钮

JButton jb = new JButton("第"+(i+1)+"张图");

int z = i;

//当按钮点击的时候

jb.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

//设置jl的图片

jl.setIcon(new ImageIcon("src\\images\\"+(z+1)+".gif"));

}

});

jp.add(jb);

}

this.setLocation(200, 120);

this.setSize(500,200);

this.setLayout(new BorderLayout());

this.add(jl);

this.add(jp,BorderLayout.SOUTH);

this.setTitle("图片浏览");

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.setVisible(true);

}

public static void main(String[] args) {

new ImageDemo();

}

}


文章名称:java好看按钮样式代码 java按钮实现功能
浏览地址:http://cdkjz.cn/article/ddehieh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220