2

我有一个程序用作实验来习惯 GUI。它基本上采用 f(x)=ax^2+bx+c 形式的二次方,并找到实数零点、y 截距和对称轴。它在计算和所有方面都运行良好。我的问题是我创建了一个不可编辑的文本框(使用窗口构建器SWT应用程序),无论我做什么,它总是在一行上打印所有内容!\n 不起作用,\r\n 不起作用...请帮助。

Button btnNewButton = new Button(shlParacalc, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {

        String aval = alphabox.getText();
        double a = Double.parseDouble(aval);

        String bval = betabox.getText();
        double b = Double.parseDouble(bval);

        String cval = gammabox.getText();
        double c = Double.parseDouble(cval);


        CalcLib mathObj = new CalcLib();    

        double yint = mathObj.yIntercept(a, b, c);
        double axis = mathObj.Axis(a, b);
        double zero[] = mathObj.Zero(a, b, c);


        outputbox.append("y-intercept = " + yint); // these four lines need
        outputbox.append("axis of symmetry = " + axis); //to be printed
        outputbox.append("1st zero = " + zero[0]); //on individual lines
        outputbox.append("2nd zero = " + zero[1]);
4

1 回答 1

1

您可能使用了错误的样式位。此代码有效:

public static void main(String[] args)
{
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);

    Button button = new Button(shell, SWT.NONE);
    button.setText("Add text");
    button.addListener(SWT.Selection, new Listener()
    {
        @Override
        public void handleEvent(Event e)
        {

            text.append("y-intercept = \n");
            text.append("axis of symmetry = \n");
            text.append("1st zero = \n");
            text.append("2nd zero = \n");
        }
    });

    shell.pack();
    shell.setSize(400, 200);
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }
    display.dispose();
}
于 2013-09-20T10:06:25.150 回答