Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Sockets and Internet Protocols
help, itsnot working no more since putting in swing!
Karis Brown
Ranch Hand
Posts: 33
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This used to work fine when I did not have it with swing features.
why is it so hard for it to work?
//A5.Write an improved version of section A3 above using //"Swing" and "threads" as you consider most appropriate. import java.io.*; import java.net.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; //<html> //<Body> //<applet code =A5PizzaProgram.class width = 700 height =200> //</applet> //</body> //</html> public class A5PizzaProgram extends JApplet implements ItemListener, ActionListener{ JButton Calc; JTextField response; String myresponse; JCheckBox Small, Medium, Large, SuperLarge, Pepporoni, Chilli, Anchovies,Ham, Mushrooms, Greenpeppers; Socket cts; DataInputStream isfs; DataOutputStream osts; double itotal, stotal; public A5PizzaProgram() { stotal =3; itotal =2; Container content = getContentPane(); JPanel PSizePanel = new JPanel(); //Pizza Sizes JPanel PsP_Output = new JPanel(); JPanel PIngPanel = new JPanel(); //Pizza Ingredients JPanel PiP_Output = new JPanel(); JPanel TotalPanel = new JPanel(); //Pizza Ingredients JPanel Total_Output = new JPanel(); JCheckBox Small = new JCheckBox("Small"); JCheckBox Medium = new JCheckBox("Medium"); JCheckBox Large = new JCheckBox("Large"); JCheckBox SuperLarge = new JCheckBox("SuperLarge"); JCheckBox Pepporoni = new JCheckBox("Pepporoni"); JCheckBox Chilli = new JCheckBox("Chilli"); JCheckBox Ham = new JCheckBox("Ham"); JCheckBox Greenpeppers = new JCheckBox("Greenpeppers"); JCheckBox Mushrooms = new JCheckBox("Mushrooms"); JCheckBox Anchovies = new JCheckBox("Anchovies"); JButton Calc= new JButton("Calculate"); response = new JTextField(10); ButtonGroup PsP = new ButtonGroup(); PsP.add(Small); PsP.add(Medium); PsP.add(Large); PsP.add(SuperLarge); PsP_Output.add(Small); PsP_Output.add(Medium); PsP_Output.add(Large); PsP_Output.add(SuperLarge); JPanel PiP = new JPanel(); PiP.add(Pepporoni); PiP.add(Chilli); PiP.add(Ham); PiP.add(Greenpeppers); PiP.add(Mushrooms); PiP.add(Anchovies); PiP_Output.add(Pepporoni); PiP_Output.add(Chilli); PiP_Output.add(Ham); PiP_Output.add(Greenpeppers); PiP_Output.add(Mushrooms); PiP_Output.add(Anchovies); JPanel Total = new JPanel(); Total.add(Calc); Total.add(response); Total_Output.add(Calc); Total_Output.add(response); Small.setSelected(false); Medium.setSelected(false); Large.setSelected(false); SuperLarge.setSelected(false); Pepporoni.setSelected(false); Chilli.setSelected(false); Ham.setSelected(false); Greenpeppers.setSelected(false); Mushrooms.setSelected(false); Anchovies.setSelected(false); Small.addItemListener(this); Medium.addItemListener(this); Large.addItemListener(this); SuperLarge.addItemListener(this); Pepporoni.addItemListener(this); Chilli.addItemListener(this); Ham.addItemListener(this); Greenpeppers.addItemListener(this); Mushrooms.addItemListener(this); Anchovies.addItemListener(this); Calc.addActionListener(this); EtchedBorder SizeLine = new EtchedBorder(); PsP_Output.setBorder(new TitledBorder(SizeLine,"Please Choose Pizza Size ")); EtchedBorder IngLine = new EtchedBorder(); PiP_Output.setBorder(new TitledBorder(IngLine,"Please Choose Toppings ")); EtchedBorder TotalLine = new EtchedBorder(); Total_Output.setBorder(new TitledBorder(TotalLine,"Your total amount you have to pay")); content.add(PsP_Output, BorderLayout.LINE_START); content.add(PiP_Output, BorderLayout.CENTER); content.add(Total_Output, BorderLayout.LINE_END); //PSizePanel.add("East",PsP_Output); //PIngPanel.add("West",PiP_Output); PsP_Output.setLayout(new GridLayout(0,2)); PiP_Output.setLayout(new GridLayout(0,1)); //setContentPane(PSizePanel); //setContentPane(PiP_Output); } //End of public void init. /*public static double getTotal() { return total; }*/ public void itemStateChanged(ItemEvent e) { Object choice = e.getItemSelectable(); /*if (choice == Small); stotal=3; if (choice == Medium); stotal=6; if (choice == Large); stotal=8; if (choice == SuperLarge); stotal=10; if(choice == Pepporoni); itotal=+ .60; if(choice == Ham); itotal=+ .60; if(choice == Greenpeppers); itotal=+ .60; if(choice == Anchovies); itotal=+ .60; if(choice == Mushrooms); itotal=+ .60; if(choice == Chilli); itotal=+ .60;*/ } /*public void actionPerformed (ActionEvent e) { if (e.getActionCommand()=="Calculate") { response.setText("� "+String.valueOf(stotal+itotal)); //response.setText(itotal+stotal); } }*/ public void actionPerformed (ActionEvent e) { try { cts = new Socket(getCodeBase().getHost(), 6000); //connect to server on the address 6000 isfs = new DataInputStream(cts.getInputStream()); //input stream from server osts = new DataOutputStream(cts.getOutputStream()); //output stream to server osts.writeDouble(stotal); //Data being sent to the server (from the client) osts.writeDouble(itotal); osts.flush();//Clueless what this does? double total = isfs.readDouble(); //this is what I am recieving from the server if (e.getSource() == Calc) { response.setText("� "+String.valueOf(total)); //now that I have recieved the the value i can output\display //response.setText("Total� "+total); //it on the screen applet. } } catch (IOException ex) { System.out.println(ex); } } }
server
import java.io.*; import java.net.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class A5ServerforPizzaApp { public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(6000); Socket ctc = ss.accept(); DataInputStream isfc = new DataInputStream(ctc.getInputStream()); //isfc input stream from client DataOutputStream ostc = new DataOutputStream(ctc.getOutputStream()); //ostc output stream from client double totala = isfc.readDouble(); //two parts of data down the same port/stream double totalb = isfc.readDouble(); System.out.println("Amount for Pizza Type: " + totala); double total = (totala+totalb); ostc.writeDouble(total); // Send through the ostc stream the value of circf ostc.flush(); System.out.println("Total amount for Ingredients: " + totalb); //how ever the dos screen window is also // outputting a message as well sending data to the applet. } catch (IOException e) { //System.out.println(e); } } }
[ April 01, 2004: Message edited by: Karis Brown ]
So Cold & So Outa Control
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Two Classes and a Public Void!
Not sending data to Server!
trying to get a value from another class
HELLP! i cant get 2 JPanels to display without them sitting on the other!
if its not one thing its another!!
More...