javaserver
来自「cqME :java framework for TCK test.」· 代码 · 共 167 行
TXT
167 行
/* * @@CLASS_NAME@@.java * * Created on @@DATE@@, @@TIME@@ */@@SERVER_PACKAGE_HEADER@@import java.awt.*;import java.awt.event.*;import java.io.IOException;import java.net.MalformedURLException;import com.sun.tck.midp.lib.DistribInteractiveTest;import com.sun.javatest.Status;public class @@CLASS_NAME@@Server extends DistribInteractiveTest { public @@CLASS_NAME@@Server() { super("YesNo", true); setName("@@CLASS_NAME@@Server"); } public void handle_runTestCase(String from, String[] args) { clientName = from; runTestCase(from, args[1]); } public void handle_endRun(String from, String[] args) { endRun(); } public void handle_test1(String from, String[] args) { } public Status test1() { String[] intro = {"Verify that the \"Hello test.\" alert created.", "Note: the sample images(180x210) taken from the reference ", "implementation can be used to validate appearance."}; initialization(intro, "", "", "test1", 1, false); setFrameSize(690, 630); return Status.passed(""); // will be ignored } protected String clientName; //////////////// private Panel controlPanel; private TextArea[] testInfo; private GridBagLayout gbl; private GridBagConstraints gbc; private void initialization(String[] intro, String title, String qn, String name, int num, boolean doubleImage) { String passMsg = "OKAY"; String failMsg = "Alert test DOES NOT work as expected."; // Add user information for (int i = 0; i < intro.length; i++) { addInfo(intro[i]); } controlPanel = new Panel(new GridLayout(1, num, 10, 10)); gbl = new GridBagLayout(); gbc = new GridBagConstraints(); testInfo = new TextArea[num]; Panel mainPanel; ImagePanel ip; Button button; ButtonListener listener; for (int i = 0; i < num; i++) { mainPanel = new Panel(gbl); button = new Button("Test " + (i+1)); gbc.gridy = 0; gbc.gridheight = 1; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(10, 10, 5, 5); gbc.anchor = GridBagConstraints.CENTER; gbc.weightx = 0.0; gbc.weighty = 0.0; gbl.setConstraints(button, gbc); listener = new ButtonListener(name, i+1); button.addActionListener(listener); mainPanel.add(button); ip = new ImagePanel(testdirurl + "images/" + name + "-" + (i+1) + ".png"); gbc.gridy = 1; gbc.gridheight = 4; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(3, 3, 3, 3); gbl.setConstraints(ip, gbc); mainPanel.add(ip); testInfo[i] = new TextArea("", 4, 20, TextArea.SCROLLBARS_VERTICAL_ONLY); testInfo[i].setEditable(false); testInfo[i].setFocusable(false); gbc.gridy = 5; gbc.gridheight = 1; gbc.insets = new Insets(5, 5, 5, 5); gbl.setConstraints(testInfo[i], gbc); mainPanel.add(testInfo[i]); controlPanel.add(mainPanel); } addTestPanel(controlPanel); // prepare the main test frame setQuestion(qn); setStatusMessages(passMsg, failMsg); setFrameTitle(title); setTimeout(180); } class ButtonListener implements ActionListener { private String test; private int index; ButtonListener(String test, int index) { this.test = test; this.index = index; } public void actionPerformed(ActionEvent e) { try { send(clientName, new String[] {test, String.valueOf(index)}); } catch (IOException ioe) { ioe.printStackTrace(); } } } class ImagePanel extends Panel { Image image1; int x = 1; ImagePanel(String s) { try { image1 = Toolkit.getDefaultToolkit().getImage(new java.net.URL(s)); } catch (MalformedURLException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } public Dimension getPreferredSize() { return new Dimension(x * 190, 210); } public Dimension getMinimumSize() { return new Dimension(x * 190, 210); } public void paint(Graphics g) { Dimension d = getSize(); g.drawImage(image1, d.width/2 - 90, 0, this); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?