我有一个程序,我正在使用它作为实验来习惯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]);
答案 0 :(得分:1)
你可能使用了错误的style bits。此代码有效:
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();
}