Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我希望java awt窗口保持打开时,它会一直关闭_Java_Modal Dialog_Awt - Fatal编程技术网

当我希望java awt窗口保持打开时,它会一直关闭

当我希望java awt窗口保持打开时,它会一直关闭,java,modal-dialog,awt,Java,Modal Dialog,Awt,各位。我的java.awt应用程序有问题 我正在使用代码制作一个轮廓图。 当我在轮廓代码中运行main函数本身时,它运行得很好,没有关闭,但是每当我想用junittestcase测试它时,它总是关闭,而我希望它保持打开 下面是轮廓绘制的原始代码 import java.awt.*; public class ColorContourPlot extends Frame implements Runnable { public ColorContourPlot() { // {{INI

各位。我的java.awt应用程序有问题

我正在使用代码制作一个轮廓图。 当我在轮廓代码中运行main函数本身时,它运行得很好,没有关闭,但是每当我想用junittestcase测试它时,它总是关闭,而我希望它保持打开

下面是轮廓绘制的原始代码

import java.awt.*;

public class ColorContourPlot
extends Frame
implements Runnable
{

public ColorContourPlot()
{
    // {{INIT_CONTROLS
    setLayout( null );
    addNotify();
    resize( insets().left + insets().right + 545, insets().top + insets().bottom + 346 );
    BackButton = new java.awt.Button( "<<" );
    BackButton.reshape( insets().left + 40, insets().top + 288, 50, 29 );
    add( BackButton );
    ForButton = new java.awt.Button( ">>" );
    ForButton.reshape( insets().left + 116, insets().top + 288, 50, 29 );
    add( ForButton );

    setTitle( "Color Contour Plot" );

    menuBar1 = new java.awt.MenuBar();

    menu1 = new java.awt.Menu( "Options" );
    menu1.add( "Contour Resolution" );
    menuBar1.add( menu1 );
    setMenuBar( menuBar1 );

    show();

    captureMode = true;
    javaVersion = new String( getJavaVersion() );

    Rectangle R = bounds();
    contourCanvas = new ColorContourCanvas( this );
    int yoffset = insets().top + insets().bottom;
    int xoffset = insets().left + insets().right;

    if ( !captureMode )
    {
        contourCanvas.reshape( insets().left + 5, insets().top + 5, R.width - xoffset - 10, R.height - yoffset - 10 );
        BackButton.hide();
        ForButton.hide();

    }
    else
    {
        contourCanvas.reshape( insets().left + 5, insets().top + 5, R.width - xoffset - 10, R.height - yoffset - 60 );
        if ( javaVersion.equals( "1.1" ) )
        {
            yoffset = 5;
        }
        BackButton.reshape( insets().left + 40, R.height - yoffset - 35, 50, 29 );
        ForButton.reshape( insets().left + 116, R.height - yoffset - 35, 50, 29 );

    }

    add( contourCanvas );

    resDialog = new ContourResolutionDialog( this, this, false );
    resDialog.hide();

    contourData = new java.util.Vector( 10 );
    currentFrame = 0;
    RunningAsThread = false;
}

java.awt.Button BackButton;

java.awt.Button ForButton;

java.awt.MenuBar menuBar1;

java.awt.Menu menu1;

public synchronized void show()
{
    move( 50, 50 );
    super.show();
}

public void repaint()
{
    Rectangle R = bounds();
    int yoffset = insets().top + insets().bottom;
    int xoffset = insets().left + insets().right;

    if ( !captureMode )
    {
        if ( contourCanvas != null )
        {
            contourCanvas.reshape( insets().left + 5, insets().top + 5, R.width - xoffset - 10, R.height - yoffset
                - 10 );
        }
    }
    else
    {
        if ( contourCanvas != null )
        {
            contourCanvas.reshape( insets().left + 5, insets().top + 5, R.width - xoffset - 10, R.height - yoffset
                - 60 );
            if ( javaVersion.equals( "1.1" ) )
            {
                yoffset = 5;
            }
            BackButton.reshape( insets().left + 40, R.height - yoffset - 35, 50, 29 );
            ForButton.reshape( insets().left + 116, R.height - yoffset - 35, 50, 29 );

        }
    }
    super.repaint();
}

public boolean handleEvent( Event event )
{
    if ( event.id == Event.WINDOW_DESTROY )
    {
        if ( !RunningAsThread )
        {
            hide(); // hide the Frame
            dispose(); // free the system resources
            System.exit( 0 ); // close the application
            return true;
        }
        else
        {
            hide();
            return true;
        }
    }

    if ( event.target == BackButton && event.id == Event.ACTION_EVENT )
    {
        BackButton_Clicked( event );
        return true;
    }
    if ( event.target == ForButton && event.id == Event.ACTION_EVENT )
    {
        ForButton_Clicked( event );
        return true;
    }
    return super.handleEvent( event );
}

public boolean action( Event event, Object arg )
{
    if ( event.target instanceof MenuItem )
    {
        String label = (String) arg;
        if ( label.equalsIgnoreCase( "Contour Resolution" ) )
        {
            ContourResolution_Action( event );
            return true;
        }
    }
    return super.action( event, arg );
}

void ForButton_Clicked( Event event )
{
    if ( currentFrame < contourData.size() )
    {
        currentFrame++;
        contourCanvas.setData( (double[][]) ( contourData.elementAt( currentFrame - 1 ) ) );

    }
}

void BackButton_Clicked( Event event )
{
    if ( currentFrame > 1 )
    {
        currentFrame--;
        contourCanvas.setData( (double[][]) ( contourData.elementAt( currentFrame - 1 ) ) );

    }
}

void ContourResolution_Action( Event event )
{
    resDialog.setResolution( contourCanvas.getResolution() );
    resDialog.show();
}

public void dialogDismissed( Dialog d )
{
    if ( d == resDialog )
    {
        int panelCount = resDialog.getResolution();
        contourCanvas.setResolution( panelCount );
        contourCanvas.repaint();
    }
}

public void setCaptureMode( boolean M )
{
    captureMode = M;
    contourData.removeAllElements();
    currentFrame = 0;
}

public void reset()
{
    contourData.removeAllElements();
    currentFrame = 0;
}

public void setDataRange( double dMin, double dMax )
{
    contourCanvas.setDataRange( dMin, dMax );
}

public void setData( double[][] inputData )
{
    if ( captureMode )
    {
        contourData.addElement( inputData );
        if ( contourData.size() == 1 )
        {
            contourCanvas.setData( inputData );

            currentFrame = 1;
        }
    }
    else
    {
        contourCanvas.setData( inputData );
    }
}

public void setData( double[] inputData, int xDataCount, int yDataCount )
{
    double[][] data = new double[xDataCount][yDataCount];
    int i;
    int j;
    for ( i = 0; i < xDataCount; i++ )
    {
        for ( j = 0; j < yDataCount; j++ )
        {
            data[i][j] = inputData[j + i * yDataCount];
        }
    }
    setData( data );
}

public void run()
{
    RunningAsThread = true;
    show();
}

public String getJavaVersion()
{
    java.util.Properties P = System.getProperties();

    java.util.StringTokenizer Tok = new java.util.StringTokenizer( P.getProperty( "java.version", null ), "." );

    String version;
    String p1, p2;
    if ( Tok.countTokens() > 1 )
    {
        p1 = Tok.nextToken();
        p2 = Tok.nextToken();
        version = p1 + "." + p2;
    }
    else
    {
        version = "1.0";
    }
    return version;
}

static public void main( String args[] )
{
    double[][] data = new double[5][5];
    for ( int i = 0; i < 5; i++ )
    {

        for ( int j = 0; j < 5; j++ )
        {
            data[i][j] = ( i * 40 ) + j;
        }
    }

    data[3][4] = 200000;
    data[2][4] = 200000;
    data[1][4] = 200000;
    data[4][4] = 200000;
    data[0][4] = 200000;

    ColorContourPlot M = new ColorContourPlot();
    M.setVisible( true );
    M.setData( M.setup2Ddata2( data ) );
}

private double[][] setup2Ddata( int n )
{
    double[][] data = new double[n][n];
    int i;
    int j;
    double x;
    double y;

    double a = -3.0; // create data for surface plot
    double b = 3.0;
    double c = -7.0;
    double d = 9.0;

    double hx = ( b - a ) / ( (double) n );
    double hy = ( d - c ) / ( (double) n );

    for ( i = 0; i < n; i++ )
    {

        for ( j = 0; j < n; j++ )
        {
            data[i][j] = ( i * 40 ) + j;
        }
    }

    data[3][10] = 0;
    data[20][30] = 85000;

    return data;

}

public double[][] setup2Ddata2( double[][] data )
{
    double[][] data2Paint = new double[data.length][data[0].length];
    int i;
    int j;
    double x;
    double y;

    double a = -3.0; // create data for surface plot
    double b = 3.0;
    double c = -7.0;
    double d = 9.0;

    for ( i = 0; i < data.length; i++ )
    {

        for ( j = 0; j < data.length; j++ )
        {
            data2Paint[i][j] = data[i][j];
        }
    }

    return data2Paint;

}

boolean RunningAsThread;

boolean captureMode;

public ColorContourCanvas contourCanvas;

ContourResolutionDialog resDialog;

String javaVersion = new String();

java.util.Vector contourData;

int currentFrame;
}
import java.awt.*;
公共类彩色曲线图
延伸框架
实现可运行
{
公共绘图()
{
//{{INIT_控件
setLayout(空);
addNotify();
调整大小(插图().左侧+插图().右侧+545,插图().顶部+插图().底部+346);
BackButton=newjava.awt.Button(“”);
ForButton.重塑(插图().左+116,插图().顶部+288,50,29);
添加(ForButton);
setTitle(“彩色等高线图”);
menuBar1=newjava.awt.MenuBar();
menu1=newjava.awt.Menu(“选项”);
菜单1.添加(“轮廓分辨率”);
menuBar1.add(menu1);
设置菜单栏(菜单栏1);
show();
captureMode=true;
javaVersion=新字符串(getJavaVersion());
矩形R=边界();
contourCanvas=新的ColorContourCanvas(本);
int yoffset=insets().top+insets().bottom;
int xoffset=insets().left+insets().right;
如果(!captureMode)
{
contourCanvas.重塑(插图().左+5,插图().顶部+5,右宽度-xoffset-10,右高度-yoffset-10);
BackButton.hide();
ForButton.hide();
}
其他的
{
contourCanvas.重塑(插图().左+5,插图().顶部+5,右宽度-xoffset-10,右高度-yoffset-60);
if(javaVersion.equals(“1.1”))
{
yoffset=5;
}
后按钮。重塑(插图()。左侧+40,右侧高度-yoffset-35,50,29);
ForButton.重塑(插图().左+116,右高-yoffset-35,50,29);
}
添加(画布);
resDialog=新轮廓分辨率Dialog(此,此,假);
resDialog.hide();
contourData=newjava.util.Vector(10);
currentFrame=0;
runningashread=false;
}
java.awt.Button BackButton;
Button for Button的java.awt.Button;
java.awt.MenuBar menuBar1;
java.awt.Menu菜单1;
公共同步的void show()
{
移动(50,50);
super.show();
}
公共无效重绘()
{
矩形R=边界();
int yoffset=insets().top+insets().bottom;
int xoffset=insets().left+insets().right;
如果(!captureMode)
{
如果(contourCanvas!=null)
{
contourCanvas.重塑(插图().左+5,插图().顶部+5,右宽度-xoffset-10,右高度-yoffset
- 10 );
}
}
其他的
{
如果(contourCanvas!=null)
{
contourCanvas.重塑(插图().左+5,插图().顶部+5,右宽度-xoffset-10,右高度-yoffset
- 60 );
if(javaVersion.equals(“1.1”))
{
yoffset=5;
}
后按钮。重塑(插图()。左侧+40,右侧高度-yoffset-35,50,29);
ForButton.重塑(插图().左+116,右高-yoffset-35,50,29);
}
}
super.repaint();
}
公共布尔handleEvent(事件)
{
if(event.id==event.WINDOW\u DESTROY)
{
如果(!runningashread)
{
hide();//隐藏帧
dispose();//释放系统资源
System.exit(0);//关闭应用程序
返回true;
}
其他的
{
隐藏();
返回true;
}
}
if(event.target==BackButton&&event.id==event.ACTION\u事件)
{
单击后按钮(事件);
返回true;
}
if(event.target==ForButton&&event.id==event.ACTION\u event)
{
ForButton_点击(事件);
返回true;
}
返回super.handleEvent(事件);
}
公共布尔操作(事件,对象参数)
{
if(event.target instanceof MenuItem)
{
字符串标签=(字符串)参数;
if(label.equalsIgnoreCase(“轮廓分辨率”))
{
行动(事件);
返回true;
}
}
返回超级动作(事件,参数);
}
已单击按钮无效(事件)
{
if(currentFrame1)
{
当前帧--;
setData((double[][])(contourData.elementAt(currentFrame-1));
}
}
无效解决措施(事件)
{
resDialog.setResolution(contourCanvas.getResolution());
resDialog.show();
}
公共作废对话框(对话框d)
{
if(d==resDialog)
{
int panelCount=resDialog.getResolution();
contourCanvas.setResolution(面板计数);
contourCanvas.repaint();
}
}
公共无效setCaptureMode(布尔值M)
{
captureMode=M;
contourData.removeAllElements();
currentFrame=0;
}
公共无效重置()
{
contourData.removeAllElements();
currentFrame=0;
}
public void setDataRange(双dMin,双dMax)
{
setDataRange(dMin,dMax);
}
public void setData(双[][]输入数据)
{
if(捕获模式)
{
轮廓数据。附加元素(输入数据);
如果(contourData.size()==1)
{
contourCanvas.setData(输入数据);
currentFrame=1;
}
}
其他的
{
contourCanvas.setData(输入数据);
}
}
public void setData(双[]输入数据,int xDataCount,int yDataCount)
{
双精度[]数据=新的双精度[xDataCount][yDataCount];
int i;
int j;
对于(i=0;ipublic class TestGraph
{

@BeforeClass
public static void setUpBeforeClass()
    throws Exception
{
}

@Test
public void test()
    throws IOException
{
    ColorContourPlot M = new ColorContourPlot();

    double[][]  data = new double[5][5];
    for(int i =0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            data[i][j] = (i*40) + j;
        }
    }

    data[3][4] = 200000;
    data[2][4] = 200000;
    data[1][4] = 200000;
    data[4][4] = 200000;
    data[0][4] = 200000;

    M.setData(M.setup2Ddata2(data));
    M.setVisible(true);
    M.setAlwaysOnTop( true );
}
}