awt实在简陋,直接放弃使用了,开始学习swing。用swing做了一个简单的程序, 才几个控件啊~但是程序启动的速度实在让我不敢恭维,要好半天才显示出来。
终于发现了swt,弄了半天,才在eclipse中装好了,ve也都装好了。于是用swt做了个简单的界面,单独在eclipse中运行界面类时,速度真是很快,也很让人满意。但是我将界面类写入到了主程序中后,主程序调用createSShell方法来生成界面,居然没有反应,界面也没出来,打包成jar又提示找不到main(打包时已经选择了main class)。
这到底是什么原因啊,网上资料实在太少~~主程序如下 import Core.Executer;
import Core.ExpressionView;//这个就是控制生成界面的类class Expression extends Thread{
public static void main(String[] args){
final ExpressionViewer view=new ExpressionViewer(); view.createSShell
//下面加入了按钮事件,以及按钮事件的处理代码。没有其他东西了
}
}
这里是界面类,使用visual editor生成的
package Core;import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.custom.CLabel;
public class ExpressionViewer { private Shell sShell = null; // @jve:decl-index=0:visual-constraint="214,-5"
public Button button = null;
private Label label = null;
public Text text = null;
public Table table = null;
private CLabel cLabel = null;
public Label result = null; /**
* This method initializes sShell
*
*/
public void createSShell() {
sShell = new Shell(SWT.BORDER | SWT.SHELL_TRIM);
sShell.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
sShell.setText("表达式分析");
sShell.setLayout(null);
sShell.setSize(new Point(564, 368));
button = new Button(sShell, SWT.UP);
button.setBounds(new Rectangle(284, 24, 107, 22));
button.setText("开始分析");
label = new Label(sShell, SWT.NONE);
label.setBounds(new Rectangle(33, 27, 66, 12));
label.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
label.setText("输入表达式");
text = new Text(sShell, SWT.BORDER);
text.setBounds(new Rectangle(102, 25, 157, 18));
table = new Table(sShell, SWT.BORDER);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setEnabled(false);
table.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_LIST_BACKGROUND));
table.setBounds(new Rectangle(15, 73, 521, 251));
TableColumn col1 = new TableColumn(table, SWT.LEFT);
col1.setText("步骤");
col1.setWidth(100);
TableColumn col2 = new TableColumn(table, SWT.LEFT);
col2.setText("栈");
col2.setWidth(100);
TableColumn col5 = new TableColumn(table, SWT.LEFT);
col5.setText("当前字符");
col5.setWidth(100);
TableColumn col3 = new TableColumn(table, SWT.LEFT);
col3.setText("剩余字符串");
col3.setWidth(100);
TableColumn col4 = new TableColumn(table, SWT.LEFT);
col4.setText("操作");
col4.setWidth(100);
cLabel = new CLabel(sShell, SWT.NONE);
cLabel.setText("分析结果:");
cLabel.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
cLabel.setBounds(new Rectangle(24, 51, 58, 23));
result = new Label(sShell, SWT.NONE);
result.setBounds(new Rectangle(94, 57, 112, 12));
result.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
result.setText("");
}}
终于发现了swt,弄了半天,才在eclipse中装好了,ve也都装好了。于是用swt做了个简单的界面,单独在eclipse中运行界面类时,速度真是很快,也很让人满意。但是我将界面类写入到了主程序中后,主程序调用createSShell方法来生成界面,居然没有反应,界面也没出来,打包成jar又提示找不到main(打包时已经选择了main class)。
这到底是什么原因啊,网上资料实在太少~~主程序如下 import Core.Executer;
import Core.ExpressionView;//这个就是控制生成界面的类class Expression extends Thread{
public static void main(String[] args){
final ExpressionViewer view=new ExpressionViewer(); view.createSShell
//下面加入了按钮事件,以及按钮事件的处理代码。没有其他东西了
}
}
这里是界面类,使用visual editor生成的
package Core;import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.custom.CLabel;
public class ExpressionViewer { private Shell sShell = null; // @jve:decl-index=0:visual-constraint="214,-5"
public Button button = null;
private Label label = null;
public Text text = null;
public Table table = null;
private CLabel cLabel = null;
public Label result = null; /**
* This method initializes sShell
*
*/
public void createSShell() {
sShell = new Shell(SWT.BORDER | SWT.SHELL_TRIM);
sShell.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
sShell.setText("表达式分析");
sShell.setLayout(null);
sShell.setSize(new Point(564, 368));
button = new Button(sShell, SWT.UP);
button.setBounds(new Rectangle(284, 24, 107, 22));
button.setText("开始分析");
label = new Label(sShell, SWT.NONE);
label.setBounds(new Rectangle(33, 27, 66, 12));
label.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
label.setText("输入表达式");
text = new Text(sShell, SWT.BORDER);
text.setBounds(new Rectangle(102, 25, 157, 18));
table = new Table(sShell, SWT.BORDER);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setEnabled(false);
table.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_LIST_BACKGROUND));
table.setBounds(new Rectangle(15, 73, 521, 251));
TableColumn col1 = new TableColumn(table, SWT.LEFT);
col1.setText("步骤");
col1.setWidth(100);
TableColumn col2 = new TableColumn(table, SWT.LEFT);
col2.setText("栈");
col2.setWidth(100);
TableColumn col5 = new TableColumn(table, SWT.LEFT);
col5.setText("当前字符");
col5.setWidth(100);
TableColumn col3 = new TableColumn(table, SWT.LEFT);
col3.setText("剩余字符串");
col3.setWidth(100);
TableColumn col4 = new TableColumn(table, SWT.LEFT);
col4.setText("操作");
col4.setWidth(100);
cLabel = new CLabel(sShell, SWT.NONE);
cLabel.setText("分析结果:");
cLabel.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
cLabel.setBounds(new Rectangle(24, 51, 58, 23));
result = new Label(sShell, SWT.NONE);
result.setBounds(new Rectangle(94, 57, 112, 12));
result.setBackground(Display.getCurrent().getSystemColor(
SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
result.setText("");
}}
swt又显示不出来,也不提示错误。真是郁闷啊
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
SSH 貌似指Struts/Spring/Hibernate三种框架吧,反正作为新手的我只知道这么多,,,,,
如果我会c++我也想用VC啊~~但是没办法么~~
再说了,java还是不错的,桌面表现虽然不如VC,但是足够了本问题已经解决,swing执行时有一个初始化线程,而主程序的main方法也占有单独一个线程,在swing完成初始化之前,主程序线程已经运行结束,或许是这个原因造成swing初始化总是失败吧~~有高手愿意回答下吗?