ACM Interactors Freeze [英] ACM Interactors Freeze

查看:132
本文介绍了ACM Interactors Freeze的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Swing和ACM交互器创建一个非常简单的程序。它直接来自课堂讲义,但不能在我的电脑上运行。当我运行它时,它可以正常运行大约半秒钟,然后短暂闪烁,重新加载,然后所有按钮和文本字段功能都会丢失。这是代码:

I'm trying to make a very simple program with Swing and ACM interactors. It is taken directly from a class handout, but does not function on my computer. When I run it, it functions fine for about half a second, then briefly flashes, reloads, and then all button and text-field functionality is lost. Here's the code:

import acm.program.*;
import java.awt.event.*;
import javax.swing.*;

public class TextFieldExample extends ConsoleProgram {

public void init() {
    nameField = new JTextField(15);
    add(new JLabel("Name: "), SOUTH);
    add(nameField, SOUTH);
    nameField.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == nameField) {
        println("Hello, " + nameField.getText());
    }
}

private JTextField nameField;
}

如果有帮助,我正在使用带有Eclipse Helios Service Release的Java SE 1.6 2在2010年中期Mac Pro上运行Mac OSX 10.8.4

If it helps, I'm using Java SE 1.6 with Eclipse Helios Service Release 2 on a mid-2010 Mac Pro running Mac OSX 10.8.4

推荐答案

作为一种解决方法,除了使用Java 1.5 ,将字段添加到 NORTH 。此外,您可能希望扩展 GraphicsProgram

As a workaround, in addition to using Java 1.5, add the field to the NORTH. Also, you may want to extend GraphicsProgram.

修改后的SSCCE:

import acm.program.*;
import java.awt.event.*;
import javax.swing.*;

public class TextFieldExample extends GraphicsProgram {

    @Override
    public void init() {
        nameField = new JTextField(15);
        add(new JLabel("Name: "), NORTH);
        add(nameField, NORTH);
        nameField.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == nameField) {
            println("Hello, " + nameField.getText());
        }
    }
    private JTextField nameField;
}

这篇关于ACM Interactors Freeze的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆