1.javaС?小程序编?????Դ??
2.å¦ä½ç¨JAVAè¯è¨ç¼å计ç®å¨å°ç¨åºï¼
3.求java经典小程序代码
javaС??????Դ??
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.JPanel;
@SuppressWarnings("serial")
public class Test extends JFrame {
private JPanel jp = new JPanel();
private JButton jb = new JButton("按钮一");
private JButton jb = new JButton("按钮二");
private JButton jb = new JButton("按钮三");
private JButton[] jb = new JButton[] { jb, jb, jb };
private JLabel jl = new JLabel("请单击按钮!");
private int count = 0;
public Test() {
for (int i = 0; i < jb.length; i++) {
jp.add(jb[i]);
}
jp.add(jl);
this.add(jp);
this.setTitle("点按钮,程源程序html源码编辑器记录单击按钮的编程vudroid官方源码次数和名字!");
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Test.this.jl.setText(jl.getText());
}
});
for (int i = 0; i < jb.length; i++) {
jb[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jb) {
Test.this.jl.setText("您单击的源码最新防洪源码是按钮一,您总共单机了" + (++count)
+ "次按钮");
} else if (e.getSource() == jb) {
Test.this.jl.setText("您单击的小程序编php源码 音乐是按钮二,您总共单机了" + (++count)
+ "次按钮");
} else if (e.getSource() == jb) {
Test.this.jl.setText("您单击的程源程序tortoisesvn下载源码是按钮三,您总共单机了" + (++count)
+ "次按钮");
}
}
});
this.setBounds(,编程 , , );
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new Test();
}
}
å¦ä½ç¨JAVAè¯è¨ç¼å计ç®å¨å°ç¨åºï¼
å ·ä½ä»£ç å¦ä¸ï¼import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Calculator extends JFrame implements ActionListener {
private JFrame jf;
private JButton[] allButtons;
private JButton clearButton;
private JTextField jtf;
public Calculator() {
//对å¾å½¢ç»ä»¶å®ä¾å
jf=new JFrame("ä»»éç计ç®å¨1.0ï¼JAVAç");
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(){
System.exit(0);
}
});
allButtons=new JButton[];
clearButton=new JButton("æ¸ é¤");
jtf=new JTextField();
jtf.setEditable(false);
String str="+-*0.=/";
for(int i=0;i<allButtons.length;i++){
allButtons[i]=new JButton(str.substring(i,i+1));
}
}
public void init(){
//å®æå¸å±
jf.setLayout(new BorderLayout());
JPanel northPanel=new JPanel();
JPanel centerPanel=new JPanel();
JPanel southPanel=new JPanel();
northPanel.setLayout(new FlowLayout());
centerPanel.setLayout(new GridLayout(4,4));
southPanel.setLayout(new FlowLayout());
northPanel.add(jtf);
for(int i=0;i<;i++){
centerPanel.add(allButtons[i]);
}
southPanel.add(clearButton);
jf.add(northPanel,BorderLayout.NORTH);
jf.add(centerPanel,BorderLayout.CENTER);
jf.add(southPanel,BorderLayout.SOUTH);
addEventHandler();
}
//æ·»å äºä»¶çå¬
public void addEventHandler(){
jtf.addActionListener(this);
for(int i=0;i<allButtons.length;i++){
allButtons[i].addActionListener(this);
}
clearButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Calculator.this.jtf.setText("");
}
});
}
//äºä»¶å¤ç
public void actionPerformed(ActionEvent e) {
//å¨è¿éå®æäºä»¶å¤ç 使计ç®å¨å¯ä»¥è¿è¡
String action=e.getActionCommand();
if(action=="+"||action=="-"||action=="*"||action=="/"){
}
}
public void setFontAndColor(){
Font f=new Font("å®ä½",Font.BOLD,);
jtf.setFont(f);
jtf.setBackground(new Color(0x8f,0xa0,0xfb));
for(int i=0;i<;i++){
allButtons[i].setFont(f);
allButtons[i].setForeground(Color.RED);
}
}
public void showMe(){
init();
setFontAndColor();
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Calculator().showMe();
}
}
求java经典小程序代码
代码如下:public class HelloWorld {
public static void main(String []args) {
int a = 3, b = 7 ;
System.out.println("Hello World!");
}
public static int f(int a, int b){
return a*a + a*b + b*b;
}
}
结果如下: