一个窗体,一个按钮,最简单的java代码怎写?
5个回答
展开全部
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);
}
}
展开全部
简单的 杨磨圆辉三角的 打印
public class Test {
/**
* 杨辉三角瞎备塌滚衫
*/
public static void main(String[] args) {
/*int [][] a = new int[9][];
for(int i = 0; i < a.length;i ++){
a[i] = new int[i];
for(int j = 0; j < a[i].length; j++){
if(( j == 0) || j == a[i].length -1 ){
a[i][j] = 1;
}else {
a[i][j] = a[i-1][j] + a[i-1][j-1];
}
}
}
for(int i = 0; i < a.length;i ++){
for(int j = 0; j < a[i].length; j++){
System.out.print(a[i][j] + "\t");
}
System.out.println();
}*/
int [][] a = new int[4][3];
for(int i = 0; i < a.length; i ++){
for(int j = 0; j < a[i].length; j ++){
a[i][j] = i*j;
}
}
for(int i = 0; i < a.length; i ++){
for(int j = 0; j < a[i].length; j ++){
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
}
}
public class Test {
/**
* 杨辉三角瞎备塌滚衫
*/
public static void main(String[] args) {
/*int [][] a = new int[9][];
for(int i = 0; i < a.length;i ++){
a[i] = new int[i];
for(int j = 0; j < a[i].length; j++){
if(( j == 0) || j == a[i].length -1 ){
a[i][j] = 1;
}else {
a[i][j] = a[i-1][j] + a[i-1][j-1];
}
}
}
for(int i = 0; i < a.length;i ++){
for(int j = 0; j < a[i].length; j++){
System.out.print(a[i][j] + "\t");
}
System.out.println();
}*/
int [][] a = new int[4][3];
for(int i = 0; i < a.length; i ++){
for(int j = 0; j < a[i].length; j ++){
a[i][j] = i*j;
}
}
for(int i = 0; i < a.length; i ++){
for(int j = 0; j < a[i].length; j ++){
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.*;
import java.awt.event.*;
public class zb {
public static void main(String[] args) {
new MyFrame("JAVA2011记事本");
}
}
class MyFrame extends Frame {
MyFrame(String s) {
super(s);
Label lblPlus1 = new Label("登陆");
TextField tf1 = new TextField(10);
Label lblPlus2 = new Label("密码");
TextField tf2 = new TextField(10);
tf2.setEchoChar('*');
add(lblPlus1);
add(tf1);
add(lblPlus2);
add(tf2);
pack();
Button b1 = new Button("取消兆乎");
Button b2 = new Button("登录");
Button b3 = new Button("注册");
Button b4 = new Button("注销");
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(b4);
setBounds(300, 300, 320, 120);
setVisible(true);
b1.addWindowListener(new Buttonsb1()); //我想在携差button b1 添加一个功能,一按辩猜皮取消就会退出窗口
this.addWindowListener(new MyWindowMonitor());
}
class MyWindowMonitor extends WindowAdapter {
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
}
class Buttonsb1 extends WindowAdapter { //这个是button b1 的取消按钮
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
}
}
import java.awt.event.*;
public class zb {
public static void main(String[] args) {
new MyFrame("JAVA2011记事本");
}
}
class MyFrame extends Frame {
MyFrame(String s) {
super(s);
Label lblPlus1 = new Label("登陆");
TextField tf1 = new TextField(10);
Label lblPlus2 = new Label("密码");
TextField tf2 = new TextField(10);
tf2.setEchoChar('*');
add(lblPlus1);
add(tf1);
add(lblPlus2);
add(tf2);
pack();
Button b1 = new Button("取消兆乎");
Button b2 = new Button("登录");
Button b3 = new Button("注册");
Button b4 = new Button("注销");
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(b4);
setBounds(300, 300, 320, 120);
setVisible(true);
b1.addWindowListener(new Buttonsb1()); //我想在携差button b1 添加一个功能,一按辩猜皮取消就会退出窗口
this.addWindowListener(new MyWindowMonitor());
}
class MyWindowMonitor extends WindowAdapter {
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
}
class Buttonsb1 extends WindowAdapter { //这个是button b1 的取消按钮
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Test extends JFrame
{
JButton jb;
public static void main(String []args){
new Test();
}
public Test()
{
jb=new JButton("按扭");
this.add(jb);
this.setSize(400,300);
this.setVisible(true);
}
}
{
JButton jb;
public static void main(String []args){
new Test();
}
public Test()
{
jb=new JButton("按扭");
this.add(jb);
this.setSize(400,300);
this.setVisible(true);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不是吧,太简单了,无人教你吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询