import java.awt.*;
import java.awt.event.*;
//import java.applet.*;
//import javax.swing.ImageIcon;
import javax.swing.*;
import java.io.*;
//画布,运行中图画部分
class Imagecanvas extends Canvas {
private static final long serialVersionUID = 1L;//保证兼容性
Toolkit tool;//工具箱
Image Im;//图像
Imagecanvas() {
setSize(300, 50);
tool = getToolkit();//返回窗体工具包
Im = tool.getImage("dj.jpg");
}
public void paint(Graphics g) {
g.drawImage(Im, 0, 0, 150, 50, this);//在画布上g上画图片Im坐标为(0,0),Graphics.top为360,Graphics.left为50
}
}
//按钮
class GongNeng extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
GongNeng() {
super("车辆管理");
setSize(250, 200);//大小
setLocation(250, 120);//位置
setResizable(false);//窗口大小是否可改变
JPanel p1 = new JPanel();//图片区
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
Imagecanvas canvas1 = new Imagecanvas();
p1.setSize(300, 150);
p1.add(canvas1);
p2.setBounds(70, 70, 200, 80);
p2.setLayout(new GridLayout(2, 1, 5, 5));
JButton number = new JButton("车辆信息");
JButton create = new JButton("新建");
Container c = getContentPane();
c.setLayout(null);
p2.add(number);
p2.add(new JLabel(" "));
p2.add(create);
add(BorderLayout.NORTH, p1);
add(BorderLayout.CENTER, p2);
add(BorderLayout.SOUTH, p3);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
}
}
class BaoCun extends WindowAdapter implements ActionListener{
Frame f;
Button btn;
//TextArea ta;
String fileName;
public class XinJian{
this.fileName=fileName;
f=new Frame();
f.addWindowListener(this);
TextField ta =new TextField(25);
btn=new Button("保存");
btn.addActionListener(this);
//ta=new TextArea(60,60);
f.add(ta,BorderLayout.CENTER);
f.add(btn,BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
//new XinJian();
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(btn)){
new XinJian();
}
}
}
public class GuanLi {
public static void main(String[] args) {
new GongNeng();
}
}
}
如果可以的话,希望能帮我弄成可执行的,我是新手,谢谢帮忙!
2 个解决方案
#1
题目说的是语法错误,你好好检查就会发现了吧..呵呵呵swing这块有两三年没弄了,看到代码都晕菜了
#2
少了个'}'
#1
题目说的是语法错误,你好好检查就会发现了吧..呵呵呵swing这块有两三年没弄了,看到代码都晕菜了
#2
少了个'}'