问个弱弱的问题 楼上的弓虽啊,007?哈~在线等ing 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JOptionPane.showConfirmDialog(this, "email地址文件有错误", "出现错误", JOptionPane.PLAIN_MESSAGE) ;这个算么 楼上的,这个不算,喉喉,我说的是JFrame 建议你看看JAVA自带的DEMO程序! 程序太场了 没时间看啊!建议去看看 SWING吧 写个JFrame派生类。在你要用的地方new一个就行。 To:射天狼老大,我上周末才开始学java滴,以前一点也不知道,这几天光看demo了swing也看了不少不过好象还没看懂啊,汗.....还有人嫌我写的程序长,这才几行啊,汗..... 对,楼上的说得没错,如果显示不了设置 setVisible(true) JFrame jframe=new JFrame();jframe.setSize(new Dimension(640, 480));jframe.setVisible(true); 哪一位给个完整的代码啊,我刚看了几天java,对整体把握太模糊,程序总出错拜托拜托各位了 放在init()方法中,最好是放在该方法的最后 老大,呜呜呜,还是不行啊,我索性把我现在的代码全贴上来吧,有两个文件一个是designer.java,一个是toolbox.javatoolbox是定义了一个简单的JFrame扩展类Designer.java如下:package module;/** * @author Administrator * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.BufferedInputStream;public class Designer extends JApplet implements ActionListener{ //ActionListener actlsnr; ImageIcon formatIcon; ImageIcon controIcon; ToolBox toolbox; protected String formatButtonFilename = "/images/format.gif"; protected String controlButtonFilename = "/images/control.gif"; public Designer(){ } public void init(){ try{ javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); toolbox = new ToolBox(); } }); }catch(Exception e){ } } private void createGUI(){ JFrame.setDefaultLookAndFeelDecorated(true); formatIcon = loadImage(formatButtonFilename); controIcon = loadImage(controlButtonFilename); JButton btnFormat = new JButton("版式",formatIcon); JButton btnControl = new JButton("控件",controIcon); btnFormat.addActionListener(this); btnControl.addActionListener(this); btnFormat.setActionCommand("shwotoolbox"); JPanel panel1= new JPanel(new FlowLayout()); panel1.setLayout(new GridLayout(2,1)); panel1.add(btnFormat); panel1.add(btnControl); panel1.setPreferredSize(new Dimension(100, 20)); add(panel1); } public void actionPerformed(ActionEvent e) { if ("shwotoolbox".equals(e.getActionCommand())) { toolbox.setVisible(true); } } public void run(){ } protected ImageIcon loadImage(String imageName) { String path = imageName ; int MAX_IMAGE_SIZE = 2400; //Change this to the size of //your biggest image, in bytes. int count = 0; BufferedInputStream imgStream = new BufferedInputStream( this.getClass().getResourceAsStream(path)); if (imgStream != null) { byte buf[] = new byte[MAX_IMAGE_SIZE]; try { count = imgStream.read(buf); imgStream.close(); } catch (java.io.IOException ioe) { System.err.println("Couldn't read stream from file: " + path); return null; } if (count <= 0) { System.err.println("Empty file: " + path); return null; } return new ImageIcon(Toolkit.getDefaultToolkit().createImage(buf)); } else { System.err.println("Couldn't find file: " + path); return null; } }}ToolBox.java如下:/* * Created on 2005-3-30 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */package module;/** * @author Administrator * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */import java.awt.*;import javax.swing.*;public class ToolBox extends JFrame{ public ToolBox(){ String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)} }; JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(400, 70)); JScrollPane scrollPane = new JScrollPane(table); this.getContentPane().add(scrollPane); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); //this.setVisible(true); }}出现的问题还是跟以前一样啊,在eclipse里面调试可以,点击第一个按纽,toolbox就能显示出来了在网页里面就是不行啊.郁闷啊,郁闷啊,郁闷啊................. 问题解决了,还是不结贴没有这一句就可以this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 关于如何得到样式中 class的属性 请教大家一个OOP编程问题,谢谢各位 在后台运行java程序,开war3.exe之后,就不能用runTime.exec()了 一些简单的问题,大家进来看看啊 一个简单的问题:&0xff 用什么啊? 请问把redhat 下的JBOSS移植到 IBM AIX下的一些问题 震惊!!! Borland推出了JBuilder 9 一个JAVA问题 JDK 1.4 Beta公开下载 关于线程捕捉异常的问题 求skinLF的使用方法 可以用远程资源来建一个对象吗
"出现错误", JOptionPane.PLAIN_MESSAGE) ;
这个算么
建议去看看 SWING吧
在你要用的地方new一个就行。
老大,我上周末才开始学java滴,以前一点也不知道,这几天光看demo了
swing也看了不少
不过好象还没看懂啊,汗.....
还有人嫌我写的程序长,这才几行啊,汗.....
jframe.setSize(new Dimension(640, 480));
jframe.setVisible(true);
一个是designer.java,一个是toolbox.java
toolbox是定义了一个简单的JFrame扩展类
Designer.java如下:
package module;/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.BufferedInputStream;
public class Designer extends JApplet implements ActionListener{
//ActionListener actlsnr;
ImageIcon formatIcon;
ImageIcon controIcon;
ToolBox toolbox;
protected String formatButtonFilename = "/images/format.gif";
protected String controlButtonFilename = "/images/control.gif";
public Designer(){
}
public void init(){
try{
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
toolbox = new ToolBox();
}
});
}catch(Exception e){
}
}
private void createGUI(){
JFrame.setDefaultLookAndFeelDecorated(true);
formatIcon = loadImage(formatButtonFilename);
controIcon = loadImage(controlButtonFilename);
JButton btnFormat = new JButton("版式",formatIcon);
JButton btnControl = new JButton("控件",controIcon);
btnFormat.addActionListener(this);
btnControl.addActionListener(this);
btnFormat.setActionCommand("shwotoolbox");
JPanel panel1= new JPanel(new FlowLayout());
panel1.setLayout(new GridLayout(2,1)); panel1.add(btnFormat);
panel1.add(btnControl);
panel1.setPreferredSize(new Dimension(100, 20));
add(panel1);
}
public void actionPerformed(ActionEvent e) {
if ("shwotoolbox".equals(e.getActionCommand())) {
toolbox.setVisible(true);
}
}
public void run(){
}
protected ImageIcon loadImage(String imageName) {
String path = imageName ;
int MAX_IMAGE_SIZE = 2400; //Change this to the size of
//your biggest image, in bytes.
int count = 0;
BufferedInputStream imgStream = new BufferedInputStream(
this.getClass().getResourceAsStream(path));
if (imgStream != null) {
byte buf[] = new byte[MAX_IMAGE_SIZE];
try {
count = imgStream.read(buf);
imgStream.close();
} catch (java.io.IOException ioe) {
System.err.println("Couldn't read stream from file: " + path);
return null;
}
if (count <= 0) {
System.err.println("Empty file: " + path);
return null;
}
return new ImageIcon(Toolkit.getDefaultToolkit().createImage(buf));
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
ToolBox.java如下:/*
* Created on 2005-3-30
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package module;/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.awt.*;
import javax.swing.*;public class ToolBox extends JFrame{
public ToolBox(){
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour",
"Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne",
"Pool", new Integer(10), new Boolean(false)}
};
JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(400, 70));
JScrollPane scrollPane = new JScrollPane(table);
this.getContentPane().add(scrollPane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
//this.setVisible(true);
}
}出现的问题还是跟以前一样啊,在eclipse里面调试可以,点击第一个按纽,toolbox就能显示出来了
在网页里面就是不行啊.郁闷啊,郁闷啊,郁闷啊.................
没有这一句就可以
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);