Java Applet 无法正确显示
我编写了一个小型java小程序作为在线表单,它将接收与订单等相关的信息...并向公司收件箱发送适当的电子邮件。我的问题是小程序未正确加载,并且程序中没有事件驱动的代码正在运行。 (这包括填充表单中的列表和选项的函数)。我问我的同事是否已将 *.class 文件放到公司网络服务器上(与正在执行的 html 代码位于同一目录中),他已经验证了这一点。
我很困惑,什么可能导致小程序无法正确加载以及什么会导致小程序无法启动事件驱动代码?这是该小程序的缩短版本(它有点长,所以请注意,请注意 get**() 等方法,它是未运行的方法之一,它会用选项填充分销商列表)。
package OrderSpecs;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Properties;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JTextField;
public class OrderSpecs extends JApplet implements ActionListener {
/**
* This is the OrderSpecs default constructor
*/
public OrderSpecs() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setPreferredSize(new Dimension(880, 1279));
this.setSize(880, 1279);
this.setContentPane(new JScrollPane(getJContentPane()));
applicationList = new ArrayList<Application>();
Date dateNow = new Date ();
SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MM/dd/yyyy");
this.dateString = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );
}
/**
* Initialize the list of industries for the drop-down list
*/
private String[] getIndustryList()
{
String[] industries =
{
" ", "Commercial Lab", "Environmental", "Food / Wine", "Government", "Marine Lab",
"Other", "Petro Chemical", "Power Generation", "Pulp & Paper", "University"
};
return industries;
}
我正在使用 Eclipse 进行小程序开发,当我编译/运行代码时,它完美地出现在我的机器上,有什么想法吗?非常感谢,
- 迈克
I've written a small java applet to act as an online form which will take in information pertaining to orders etc... and sent appropriate emails to company inboxes. My problem is that the applet is not loading correctly and that none of the event-driven code in the program is running. (This includes functions which populate lists and choices within the form). I've asked my co-worker if he has put up the *.class file onto the company webserver (in the same directory as the html code being executed), and he has verified that he has.
I'm stumped, what could be causing the applet to be failing to load properly and what would cause the applet not to able to fire-off event driven code? Here is the applet in a shortened version (it's a little lengthy so look out, really draw your attention to methods like the get**(), which is one of the methods which isn't running, it populates the distributor list with choices).
package OrderSpecs;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Properties;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JTextField;
public class OrderSpecs extends JApplet implements ActionListener {
/**
* This is the OrderSpecs default constructor
*/
public OrderSpecs() {
super();
}
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setPreferredSize(new Dimension(880, 1279));
this.setSize(880, 1279);
this.setContentPane(new JScrollPane(getJContentPane()));
applicationList = new ArrayList<Application>();
Date dateNow = new Date ();
SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MM/dd/yyyy");
this.dateString = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );
}
/**
* Initialize the list of industries for the drop-down list
*/
private String[] getIndustryList()
{
String[] industries =
{
" ", "Commercial Lab", "Environmental", "Food / Wine", "Government", "Marine Lab",
"Other", "Petro Chemical", "Power Generation", "Pulp & Paper", "University"
};
return industries;
}
I'm using Eclipse for applet development and when I compile / run the code it appears perfectly on my machine, any ideas? Thanks a lot,
- Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您如何定义文本字段。如果您使用:
那么文本字段的大小将等于文本的大小,在本例中为 0。您应该使用如下所示的内容来给出首选大小:
同样,我们无法从发布的代码中判断您在做什么,因此我们无法提供任何帮助。
那么问题是为什么你要编写一个很长的程序而不进行任何调试?首先创建一个 10 行程序,该程序仅创建一个组合框、向模型添加数据并在 GUI 上显示组合框。如果效果很好,现在您可以将工作代码与您的程序进行比较,看看您做了什么不同的事情。
如果它不起作用,那么您可以将一个简单的完整程序发布在论坛上。这称为 SSCCE。否则我们只是在胡乱猜测,这并不能很好地利用我们的时间。
Well that depends on how you define the text field. If you use:
Then the text field will have a size equal to the text which in this case is 0. You should be using something like the following to give a preferred size:
Again we can't tell from the posted code what you are doing so we can't offer any help.
So the question is why are you writing a program that is very long without doing any debugging along the way? Start by creating a 10 line program that simply creates a combo box, adds data to the model and displays the combo box on the GUI. If it works great, now you can compare the working code with your program to see what you are doing differently.
If it doesn't work then you have a simple complete program to post on the forum. This is called a SSCCE. Otherwise we are just making wild guesses which is not very good use of our time.