import java.awt.*; import java.applet.*; import java.io.*; import java.net.*; import java.util.*; public class DistribControls extends Panel { GridBagLayout gbl; GridBagConstraints gbc; Label distLabel; Label distNameLabel; TextField distNameTxt; Label distTypeLabel; Choice typeChoice; private void add(Component c, GridBagLayout gbl, GridBagConstraints gbc, int x, int y, int w, int h) { gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; gbl.setConstraints(c,gbc); add(c); } public void paint(Graphics g) { Dimension d = size(); Insets in = insets(); Font f = new Font("TimesRoman", Font.BOLD, 14); FontMetrics fm = g.getFontMetrics(f); String s = "DISTRIBUTION"; g.setFont(f); //g.drawString(s, d.width/4+50, d.height/4-40); g.drawRect(0, 0, d.width-1, d.height-1); } public DistribControls() { gbl = new GridBagLayout(); setLayout(gbl); distLabel = new Label("DISTRIBUTION",Label.CENTER); //distLabel.setBackground(Color.yellow); distLabel.setForeground(Color.blue); distNameLabel = new Label("Name :",Label.RIGHT); distNameTxt = new TextField(); distTypeLabel = new Label("Type :",Label.RIGHT); typeChoice = new Choice(); typeChoice.addItem("Block1dim"); typeChoice.addItem("Block2dim"); typeChoice.addItem("Block3dim"); Label blankLabel = new Label(" "); gbc = new GridBagConstraints(); gbc.weightx = 1; gbc.weighty = 100; gbc.fill = GridBagConstraints.HORIZONTAL; //gbc.anchor = GridBagConstraints.WEST; add(distLabel, gbl, gbc, 0, 0, 4, 1); add(distNameLabel, gbl, gbc, 0, 1, 1, 1); add(distNameTxt, gbl, gbc, 1, 1, 1, 1); add(distTypeLabel, gbl, gbc, 0, 2, 1, 1); add(typeChoice, gbl, gbc, 1, 2, 1, 1); add(blankLabel, gbl, gbc, 2, 2, 1, 1); } public Insets insets() { return new Insets(5,5,5,5); } public void setExample(String str) { int count, i; clearAll(); String s; StringTokenizer t = new StringTokenizer(str, " "); s = t.nextToken(); distNameTxt.setText(s); s = t.nextToken(); //System.out.println(">> :" + s); typeChoice.select(s); } public void clearAll() { remove(typeChoice); distNameTxt.setText(""); typeChoice.select("Block1dim"); add(typeChoice, gbl, gbc, 1, 2, 1, 1); } public void sendInputToServer(DataOutputStream os) { try { os.writeBytes("dist.ini"); os.writeByte('\n'); os.writeBytes(distNameTxt.getText()+" "); os.writeBytes(typeChoice.getSelectedItem()); os.writeByte('\n'); os.writeBytes("end"); os.writeByte('\n'); } catch (IOException e) { System.err.println("I/O failed on the connection to: taranis"); } } };