当前位置: 代码迷 >> Java相关 >> 为何在eclipse中显示“已终止 Java应用程序”?
  详细解决方案

为何在eclipse中显示“已终止 Java应用程序”?

热度:1433   发布时间:2011-09-02 23:55:03.0
为何在eclipse中显示“已终止 Java应用程序”?
写了一个小的图形界面程序,运行时出现“已终止 Java应用程序”
这是怎么回事啊?
搜索更多相关的解决方案: 应用程序  Java  

----------------解决方案--------------------------------------------------------
代码发来看看
----------------解决方案--------------------------------------------------------
程序代码:
package cn.vts;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Vector;
import javax.swing.JPanel;

public class J_Panel extends JPanel
{
    private Vector<Vector<Point>> m_vectorSet
        = new Vector<Vector<Point>>( );

    public J_Panel( )
    {
        addMouseListener( new MouseListener( )
            {
                public void mouseClicked(MouseEvent e)
                {
                } // 方法mouseClicked结束

                public void mouseEntered(MouseEvent e)
                {
                } // 方法mouseEntered结束

                public void mouseExited(MouseEvent e)
                {
                } // 方法mouseExited结束

                public void mousePressed(MouseEvent e)
                {
                    Point p= new Point(e.getX( ), e.getY( ));
                    Vector<Point> v= new Vector<Point>( ); // 新的笔划
                    v.add(p); // 添加笔划的起点
                    m_vectorSet.add(v);
                } // 方法mousePressed结束

                public void mouseReleased(MouseEvent e)
                {
                } // 方法mouseReleased结束
            } // 实现接口MouseListener的内部类结束
        ); // addMouseListener方法调用结束
        addMouseMotionListener( new MouseMotionListener( )
            {
                public void mouseMoved(MouseEvent e)
                {
                } // 方法mouseMoved结束

                public void mouseDragged(MouseEvent e)
                {
                    Point p= new Point(e.getX( ), e.getY( ));
                    int n= m_vectorSet.size( )-1;
                    Vector<Point> v= m_vectorSet.get(n);
                    v.add(p); // 添加笔划的中间点或终点
                    repaint( );
                } // 方法mouseDragged结束
            } // 实现接口MouseMotionListener的内部类结束
        ); // addMouseMotionListener方法调用结束
    } // J_Panel构造方法结束

    protected void paintComponent(Graphics g)
    {
        g.clearRect(0 , 0, getWidth( ), getHeight( )); // 清除背景
        Vector<Point> v;
        Point s, t;
        int i, j, m;
        int n= m_vectorSet.size( );
        for (i=0; i<n; i++)
        {
            v= m_vectorSet.get(i);
            m= v.size( )-1;
            for (j=0; j<m; j++)
            {
                s= (Point)v.get(j);
                t= (Point)v.get(j+1);
                g.drawLine(s.x, s.y, t.x, t.y);
            } // 内部for循环结束
        } // 外部for循环结束
    } // 方法paintComponent结束

    public Dimension getPreferredSize( )
    {
        return new Dimension( 250, 120 );
    } // 方法getPreferredSize结束
} // 类J_Panel结束


[ 本帖最后由 紫凤双飞 于 2011-9-3 00:22 编辑 ]
----------------解决方案--------------------------------------------------------
程序代码:
package cn.vts;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import cn.vts.J_Panel;

public class J_Draw extends JFrame
{
    public J_Draw( )
    {
        super( "随手画例程" );
        Container c = getContentPane( );
        c.add( new J_Panel( ),  BorderLayout.CENTER);
    } // J_Draw构造方法结束

    public static void main(String args[ ])
    {
        J_Draw app = new J_Draw( );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setSize( 270, 150 );
        app.setVisible( true );
    } // 方法main结束
} // 类J_Draw结束



----------------解决方案--------------------------------------------------------
没问题呀

----------------解决方案--------------------------------------------------------
回复 5楼 czsbc
你可以执行吗?
----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------
回复 7楼 czsbc
对了,顺便问一下如何使eclipse启动时打开空环境啊?
----------------解决方案--------------------------------------------------------
window-->perferences-->General-->Startup and Shutdown-->Prompt for workspace on startup
这样可以每次进入时选择工作区间,你说的进入空工作区间,我也不清楚怎么弄
----------------解决方案--------------------------------------------------------
  相关解决方案