//改好,实测通过
专注于为中小企业提供成都网站设计、做网站、成都外贸网站建设公司服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业牟定免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了近1000家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JFrame;
public class paint extends Canvas{//继承画布
Vector v=new Vector();
Vector vec=new Vector();
public void paint(Graphics g){
int[] x,y;
for(int j=0;jvec.size();j++){
x=new int[((Vector)vec.get(j)).size()];
y=new int[((Vector)vec.get(j)).size()];
for(int i=0;i((Vector)vec.get(j)).size();++i){
Point p=(Point)((Vector)vec.get(j)).get(i);
x[i]=p.x;
y[i]=p.y;
}
g.drawPolyline(x,y,((Vector)vec.get(j)).size());
}
}
public void init(){
vec.add(v);
addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e1){
Point p=e1.getPoint();
v.add(p);
repaint();
}
});
addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent e2){
v=new Vector();
vec.add(v);
}
});
}
public static void main(String[] args){//增加程序入口
JFrame f = new JFrame();//新建窗口对象,并将画布放入其中
f.setSize(200,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
paint p = new paint();
p.init();
f.add(p);
f.setVisible(true);
}
}
用swing可实现界面 java2exe软件可将java转化exe
java程序本身实现在java vm上 转化后就不能跨平台了 只能在windows上运行
是的 swing是的java的lib 你可以搜索下添加到lib下即可 转化exe需要下载软件
package com.swing.skip;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* 窗口跳转
* @author lichen
* @time 2013-1-16
*/
public class CloseSkip extends JFrame{
JFrame frame1;
public void win1(){
frame1=new JFrame("test1");
JPanel panel=new JPanel(true);
JButton btn1=new JButton("Start");
panel.add(btn1);
frame1.add(panel);
btn1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new CloseSkip().win2(frame1);
}
});
frame1.setBounds(300, 200, 500, 200);
frame1.setVisible(true);
frame1.setResizable(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void win2(JFrame frame){
frame.setVisible(false);
JFrame frame2=new JFrame("test2");
JPanel panel=new JPanel(true);
JButton btn2=new JButton("Stop");
panel.add(btn2);
frame2.add(panel);
frame2.setBounds(1000, 100, 200, 600);
frame2.setVisible(true);
frame2.setResizable(true);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new CloseSkip().win1();
}
}
可你个例子,参考下!~
其实你说的关闭旧窗口,就是隐藏了,使其看不见吧。下面给出一个例子,有问题百度Hi我!~
import java.awt.Container;
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;
public class TanChuShiJian extends JFrame implements ActionListener {
public TanChuShiJian() {
// TODO Auto-generated constructor stub
Container c = getContentPane();
c.setLayout(null);
JButton b = new JButton("测试");
b.addActionListener(this); //为按钮添加事件
b.setBounds(10, 10, 150, 30);
c.add(b);
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if("测试".equals(e.getActionCommand())) {
new NewFrame();
setVisible(false);
}
}
public static void main(String[] args) {
new TanChuShiJian();
}
}
class NewFrame extends JFrame {
public NewFrame() {
// TODO Auto-generated constructor stub
Container c = getContentPane();
JPanel p = new JPanel();
p.add(new JLabel("我是新窗口!"));
c.add(p);
setSize(200, 300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}