Java的朋友们请进!(100分)

  • 主题发起人 主题发起人 hongfei
  • 开始时间 开始时间
H

hongfei

Unregistered / Unconfirmed
GUEST, unregistred user!
我的JDK总是有问题!帮我编译一下代码!将生成的.class文件和应用程序文件发给我!
hongfei9999@163.com
//————————————————————————————————————————————
package myclass;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: 310</p>
* @author hongfei
* @version 1.0
*/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit;
class CalPanel extends JPanel
implements ActionListener{
private JTextField display;
private boolean start=true;
privatedo
uble arg=0;
private String op="=";
private JPopupMenu popup;
private JMenuItem itemExit;
CalPanel(){
popup=new JPopupMenu();
itemExit=new JMenuItem("Exit");
itemExit.setFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,13));
itemExit.addActionListener(this);
popup.add(itemExit);
setLayout(new BorderLayout());
//add display
JPanel p1=new JPanel();
p1.setBorder(BorderFactory.createRaisedBevelBorder());
p1.setLayout(new GridLayout(1,1));
display=new JTextField("0");
display.setFont(new Font("SansSerif",Font.BOLD,20));
display.setEditable(false);
display.setForeground(getBackground().red);
display.setBackground(getBackground().darkGray);
display.addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent evt) {
if(evt.isPopupTrigger())
popup.show(evt.getComponent(),evt.getX(),evt.getY());
}
});
p1.add(display);
add(p1,"North");
//add GridLayout
JPanel p=new JPanel();
p.setBorder(BorderFactory.createRaisedBevelBorder());
p.setLayout(new GridLayout(4,4,2,2));
String buttons="789/456*123-0.=+";
for(int i=0;i<buttons.length();i++)
addButton(p,buttons.substring(i,i+1));
add(p,"Center");
}
public void actionPerformed(ActionEvent evt){
Object str=evt.getSource();
if(str==itemExit)
System.exit(0);
String s=evt.getActionCommand();
if('0'<=s.charAt(0)&amp;&amp;s.charAt(0)<='9'||s.equals(".")){
if(start)display.setText(s);
else
display.setText(display.getText()+s);
start=false;
}//if
else
{
if(start){
if(s.equals("-"))
{display.setText(s);start=false;}
else
op=s;
}
else
{
do
uble x=Double.parseDouble(display.getText());
calculate(x);
op=s;
start=true;
}
}
}
public void calculate(double n){
if(op.equals("+"))arg+=n;
else
if (op.equals("-"))arg-=n;
else
if(op.equals("*"))arg*=n;
else
if(op.equals("/")){
if(n==0) JOptionPane.showMessageDialog(this,"Input a wrong number!","Message",JOptionPane.OK_OPTION);
else
arg/=n;}
else
if(op.equals("="))arg=n;
display.setText(""+arg);
}
private void addButton(Container c,String s){
Font f=new Font("SansSerif",Font.BOLD,18);
JButton b=new JButton(s);
b.setForeground(getBackground().green);
b.setBackground(getBackground().darkGray);
b.setActionCommand(s);
b.setFont(f);
b.addActionListener(this);
c.add(b);
//add PopupMenu
b.addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent evt) {
if(evt.isPopupTrigger())
popup.show(evt.getComponent(),evt.getX(),evt.getY());
}
});
}
}
class AboutDialog extends JDialog{
private JButton okButton;
public AboutDialog(JFrame parent){
super(parent,"About",true);
JPanel p=new JPanel();
okButton=new JButton("OK");
okButton.setFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,13));
p.add(okButton);
getContentPane().add(p,"South");
JPanel p1=new JPanel();
p1.setBorder(BorderFactory.createEtchedBorder());
p1.setLayout(new GridLayout(4,2));
p1.add(new Label("Copyright"));
p1.add(new Label("@2002"));
p1.add(new Label("Company:"));
p1.add(new Label("310"));
p1.add(new Label("Author:"));
p1.add(new Label("Hongfei"));
p1.add(new Label("Version:"));
p1.add(new Label("1.0"));
getContentPane().add(p1,"Center");
JPanel p2=new JPanel();
p2.setBorder(BorderFactory.createEtchedBorder());
p2.setLayout(new GridLayout(1,2));
p2.add(new Label("Product:"));
p2.add(new Label("My First Java"));
getContentPane().add(p2,"North");
setSize(180,180);
setLocation(310,280);
setResizable(false);
okButton.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent evt)
{setVisible(false);
}
});
}
}
class FirstFrame extends JFrame
implements ActionListener{
private AboutDialog about;
public FirstFrame(){
setTitle("My First Java Frame");
setResizable(false);
setSize(200,270);
setLocation(300,200);
//add Popupmenu
Container contentPane=getContentPane();
contentPane.add(new CalPanel());
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
JMenu fileMenu=new JMenu("File");
fileMenu.setFont(new Font("SansSerif",Font.BOLD,13));
JMenuItem ExitItem=new JMenuItem("Exit");
ExitItem.setFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,13));
ExitItem.addActionListener(this);
fileMenu.add(ExitItem);
JMenu helpMenu=new JMenu("Help");
helpMenu.setFont(new Font("SansSerif",Font.BOLD,13));
JMenuItem AboutItem=new JMenuItem("About");
AboutItem.setFont(new Font("SansSerif",Font.BOLD+Font.ITALIC,13));
AboutItem.addActionListener(this);
helpMenu.add(AboutItem);
JMenuBar myBar=new JMenuBar();
myBar.add(fileMenu);
myBar.add(helpMenu);
this.setJMenuBar(myBar);
}
public void actionPerformed(ActionEvent evt){
String str=evt.getActionCommand();
if(str=="About"){
if(about==null)
about=new AboutDialog(this);
about.show();
}
if(str=="Exit")
System.exit(0);
}
}
public class abcdef{
private JFrame frame;
public abcdef() {
frame=new FirstFrame();
Toolkit tk=Toolkit.getDefaultToolkit();
frame.setIconImage(tk.getImage("java.gif"));
frame.show();
}
public static void main(String[] args) {
abcdef abcdef1 = new abcdef();
}
}
//————————————————————————————————————————————————————————
如有人该进以上代码,请发一份给我。谢谢!
hongfei9999@163.com
 
sended to you,check it.
 
向雅你好!
请看:
http://delphibbs.com/delphibbs/dispq.asp?lid=1428878;
你用过JBuilder 7吗?能把Java abcdef的结果发给我吗?
 
我已经发到你的邮箱了了这个hongfei9999@163.com,一个rar文件,
如果你没有收到,请提供另外的邮箱。
 
喔,看错了,运行结果是一个背景黑黑的窗口,一个计算器。我没有同它进行任何交互,
只是看了看画面,还不错啊。
 
设置好classpath和path,没有理由不能正常编译啊!
 
给个C(清除功能)就好了.
 
后退
顶部