打开一个别人的文件,一堆.java, 怎么知道main函数在哪里?

[复制链接]
查看11 | 回复2 | 2008-1-16 09:04:13 | 显示全部楼层 |阅读模式
导入到eclipse的java工程,然后对工程选择运行,选后会查询所有还有main的类,你选择一个运行即可。
回复

使用道具 举报

千问 | 2008-1-16 09:04:13 | 显示全部楼层
向下边用java开发的一个计数器的程序它的文件名用计算器.java用记事本打开代码如下:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.lang.*;public class jsq {JFrame f = new JFrame("计数器");JMenuBar menubar1 = new JMenuBar();JMenu menu1 = new JMenu("编辑");JMenu menu2 = new JMenu("帮助");JTextField text = new JTextField("", 10);JButton bc = new JButton("清除");JPanel p1 = new JPanel();JPanel p2 = new JPanel();FlowLayout fl = new FlowLayout(10, 10, 10);JButton b1 = new JButton("1");JButton b2 = new JButton("2");JButton b3 = new JButton("3");JButton bx = new JButton("*");JButton b4 = new JButton("4");JButton b5 = new JButton("5");JButton b6 = new JButton("6");JButton bch = new JButton("/");JButton b7 = new JButton("7");JButton b8 = new JButton("8");JButton b9 = new JButton("9");JButton bjj = new JButton("+");JButton b0 = new JButton("0");JButton bd = new JButton(".");JButton bj = new JButton("-");JButton bdy = new JButton("=");public String shu1,shu2;double add1;char op;private boolean hasdot=false ,hasfuhao=false; // 判断小数点//boolean hasfuhao = false; // 判断是否有运算符号private boolean panduan=false;public jsq() {}public static void main(String args[]) {
jsq j1 = new jsq();
j1.go();}public void go() {
text.setHorizontalAlignment(JTextField.RIGHT);
menubar1.add(menu1);
menubar1.add(menu2);
f.setJMenuBar(menubar1);
f.getContentPane().add("North", p1);
f.getContentPane().add("Center", p2);
p1.add(text);
p1.add(bc);
p2.setLayout(fl);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(bx);
p2.add(b4);
p2.add(b5);
p2.add(b6);
p2.add(bch);
p2.add(b7);
p2.add(b8);
p2.add(b9);
p2.add(bjj);
p2.add(b0);
p2.add(bd);
p2.add(bj);
p2.add(bdy);
bc.addActionListener(new JMenuHandler(10));
b1.addActionListener(new JMenuHandler(1));
b2.addActionListener(new JMenuHandler(2));
b3.addActionListener(new JMenuHandler(3));
b4.addActionListener(new JMenuHandler(4));
b5.addActionListener(new JMenuHandler(5));
b6.addActionListener(new JMenuHandler(6));
b7.addActionListener(new JMenuHandler(7));
b8.addActionListener(new JMenuHandler(8));
b9.addActionListener(new JMenuHandler(9));
b0.addActionListener(new JMenuHandler(0));
bd.addActionListener(new JMenuHandler2());
if (!panduan) { //第一次按这些按钮,就进行JMenuhandler1()监听
bx.addActionListener(new JMenuHandler1());
bch.addActionListener(new JMenuHandler1());
bjj.addActionListener(new JMenuHandler1());
bj.addActionListener(new JMenuHandler1());
}
else { //第二次按这些按钮,等同于等于的作用
bx.addActionListener(new JMenuHandler3());
bch.addActionListener(new JMenuHandler3());
bjj.addActionListener(new JMenuHandler3());
bj.addActionListener(new JMenuHandler3());
}
// bdy.addActionListener(new JMenuHandler3());
f.setSize(220, 280);
f.setVisible(true);}class JMenuHandler
implements ActionListener {
private int ch;
public JMenuHandler(int select) {
ch = select;
}
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();//得到所按的按钮对应的值
switch (ch) {
case 10:
text.setText("");
hasdot = false;
hasfuhao = false;
panduan=false;
break;
case 0:
text.setText(text.getText() + s);
break;
case 1:
text.setText(text.getText() + s);
break;
case 2:
text.setText(text.getText() + s);
break;
case 3:
text.setText(text.getText() + s);
break;
case 4:
text.setText(text.getText() + s);
break;
case 5:
text.setText(text.getText() + s);
break;
case 6:
text.setText(text.getText() + s);
break;
case 7:
text.setText(text.getText() + s);
break;
case 8:
text.setText(text.getText() + s);
break;
case 9:
text.setText(text.getText() + s);
break;
}
}}class JMenuHandler1
implements ActionListener {//对运算符进行监听
public JMenuHandler1() {
}
public void actionPerformed(ActionEvent e) {
if (text.getText().equals("")) {
text.setText("");
}
else
if(!hasfuhao){
op = e.getActionCommand().charAt(0); //取得输入的运算符
if (!panduan) {
//是第一次按此按钮
shu1 = text.getText();
//对第一次输入的数据进行记录
panduan = true;
text.setText("");}
else{
shu2=text.getText();
System.out.println(shu2);
}
//System.out.println(shu1);
hasfuhao = true; //不能再输入运算符
hasdot = false; //可以再次输入小数点
}
}
}
class JMenuHandler2
implements ActionListener {//对小数点进行监听
//String ch1=text.getText();
public JMenuHandler2() {
}
public void actionPerformed(ActionEvent e) {
if(!text.getText().equals(""))
if (!hasdot) {
//数中没有小数点
String str;
str = text.getText() + e.getActionCommand();
text.setText(str);
//显示小数点
hasdot = true;
//有小数点
}
}
}class JMenuHandler3
implements ActionListener {
//对等于号进行监听
public JMenuHandler3() {
double add1 = Double.parseDouble(shu1);
//把shu1由string型转换成double型
System.out.println(add1);
}
double add1 = Double.parseDouble(shu1);
double shu2 = Double.parseDouble(text.getText());//类型转换,同上
public void actionPerformed(ActionEvent e) {
switch (op) {
case '+':
add1 = add1 + shu2;
break;
case '-':
add1 = add1 - shu2;
break;
case '*':
add1 = add1 * shu2;
break;
case '/':
add1 = add1 / shu2;
break;
}
if(panduan){
hasfuhao = false; //可以重新输入运算符
panduan = false;
}else{
op=e.getActionCommand().charAt(0);//新的运算符放到op中
hasfuhao=true;
}
hasdot = false; //可以重新输入小数点
text.setText(add1 + ""); //强制类型转换
}
}}在public static void main(String args[])出现main我们就可肯定它就main函数,一般出现main的是主函数。
回复

使用道具 举报

千问 | 2008-1-16 09:04:13 | 显示全部楼层
CTRL+F
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行