编一个简单的程序。 界面几个按钮,每点击一次,数字加1,例如点击了4次,则显示4。用C++或JAVA学什么?

用JAVA写一个按钮程序,单击按钮按钮上的数字就自动加1,点一次加一次。 然后,在同一个页面上再弄一个按~

import javax.swing.*;
import java.awt.event.*;
public class UITest extends JFrame implements ActionListener{
JButton button;
int count;
UITest(){
count = 0;
button = new JButton("有效按钮:"+count);
button.addActionListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(button);
this.setSize(300,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
count++;
button.setText(""+count);
this.add(new JButton(""+count));
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法
new UITest();

}

}

Private Sub Command1_Click()
Text1.Text = CInt(Text1.Text) + 1
End Sub

我这个是JAVA的,要学习

1.swing图形编程。主要是JFrame,JButton

2.swing事件编程。主要是JButton的ActionListener

3.Integer类,用于String到int的转换。

4.语法知识:匿名内部类,接口

5.必要工具:JDK的文档(API)

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonActionFrame extends JFrame {
public static void main(String[] args) {
new ButtonActionFrame();
}
public ButtonActionFrame() {
this.setSize(600, 450);
this.setLayout(new FlowLayout());
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
add(createButton());
add(createButton());
add(createButton());
add(createButton());
this.setVisible(true);
}
private JButton createButton() {
final JButton button = new JButton("0");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i = Integer.parseInt(button.getText());
button.setText(String.valueOf(i + 1));
}
});
return button;
}
}


VB编写界面最方便,能直接在图形界面进行布局,其他语言只能靠代码布局,对初学者来说有点复杂。
如果涉及较复杂的计算,可以用其他语言写dll,再用界面来调用。不过想你所说的这种程度,只用VB就够了。
随便买本VB入门教材学学就可以了,我自己觉得《Visual Basic 2010入门经典》挺好的。

.NET可以. winfrom做很简单1分钟就可以了

相关兴趣推荐

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网