Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,217,698 members, 8,035,151 topics. Date: Monday, 23 December 2024 at 04:12 AM |
Nairaland Forum / Science/Technology / Programming / I Need Help In Java Programming. (3636 Views)
Can An Array In Java Hold Multiple Types? / Community Service | I Am To Teach Everything I Know In Java For Free! / See 10 Year Old Wonder Kid Who Scored Full Marks In Java Exam Within 18mins (2) (3) (4)
I Need Help In Java Programming. by liliian(f): 3:54pm On Oct 23, 2015 |
Thanks. |
Re: I Need Help In Java Programming. by timex4u(m): 5:17pm On Oct 23, 2015 |
... |
Re: I Need Help In Java Programming. by timex4u(m): 5:18pm On Oct 23, 2015 |
//Lilian... Check this out. package concurrency; import java.util.List; import java.util.Random; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.border.Border; import javax.swing.BorderFactory; import javax.swing.SwingWorker; public class Flipper extends JFrame implements ActionListener { private final GridBagConstraints constraints; private final JTextField headsText, totalText, devText; private final Border border = BorderFactory.createLoweredBevelBorder(); private final JButton startButton, stopButton; private FlipTask flipTask; private JTextField makeText() { JTextField t = new JTextField(20); t.setEditable(false); t.setHorizontalAlignment(JTextField.RIGHT); t.setBorder(border); getContentPane().add(t, constraints); return t; } private JButton makeButton(String caption) { JButton b = new JButton(caption); b.setActionCommand(caption); b.addActionListener(this); getContentPane().add(b, constraints); return b; } public Flipper() { super("Flipper" ) ; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Make text boxes getContentPane().setLayout(new GridBagLayout()); constraints = new GridBagConstraints(); constraints.insets = new Insets(3, 10, 3, 10); headsText = makeText(); totalText = makeText(); devText = makeText(); //Make buttons startButton = makeButton("Start" ) ; stopButton = makeButton("Stop" ) ; stopButton.setEnabled(false ) ; //Display the window. pack(); setVisible(true); } private static class FlipPair { private final long heads, total; FlipPair(long heads, long total) { this.heads = heads; this.total = total; } } private class FlipTask extends SwingWorker<Void, FlipPair> { @Override protected Void doInBackground() { long heads = 0; long total = 0; Random random = new Random(); while (!isCancelled()) { total++; if (random.nextBoolean()) { heads++; } publish(new FlipPair(heads, total)); } return null; } @Override protected void process(List<FlipPair> pairs) { FlipPair pair = pairs.get(pairs.size() - 1); headsText.setText(String.format("%d", pair.heads)); totalText.setText(String.format("%d", pair.total)); devText.setText(String.format("%.10g", ((double) pair.heads)/((double) pair.total) - 0.5)); } } public void actionPerformed(ActionEvent e) { if ("Start" == e.getActionCommand()) { startButton.setEnabled(false); stopButton.setEnabled(true); (flipTask = new FlipTask()).execute(); } else if ("Stop" == e.getActionCommand()) { startButton.setEnabled(true); stopButton.setEnabled(false); flipTask.cancel(true); flipTask = null; } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Flipper(); } }); } } |
Re: I Need Help In Java Programming. by liliian(f): 6:15pm On Oct 23, 2015 |
timex4u: <xsl:template match="/"> <html> <body> <h1>Itinerary</h1><br /> <xsl:apply-templates/><br/> </body> </html> </xsl:template> <xsl:template match="env:Envelope/env:Body/p:itinerary/p:departure"> <p> <xsl:apply-templates select="p:departing"/> <xsl:apply-templates select="p:arriving"/> <xsl:apply-templates select="p:departureDate"/> </p> </xsl:template> <xsl:template match="p:departing"> Departure location: <xsl:value-of select="."/> </xsl:template> <xsl:template match="p:arriving"> Arriving location: <xsl:value-of select="."/> </xsl:template> <xsl:template match="p:departureDate"> Departure date: <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> |
Re: I Need Help In Java Programming. by timex4u(m): 6:31pm On Oct 23, 2015 |
Well said, Posted that to show you there's someone who has a clue of what u want, and also for the codes to serve as a guide 4 u bin 4rm Java's doc. site. You could pick the codes as a clue since you know quite well bout d assignment... Can give you what you want exactly, without a dime, but nt urgently... |
Re: I Need Help In Java Programming. by liliian(f): 6:32pm On Oct 23, 2015 |
timex4u: Okay,i sent you a mail.Talk to me there. |
Re: I Need Help In Java Programming. by Standing5(m): 7:08pm On Oct 23, 2015 |
The concurrency thing is not clear to me. Is it to perform multiple task of choice that will be initiated from the swing interface concurrently or some defined task? I think it revolves around java multi-threading and Swing GUI. |
Re: I Need Help In Java Programming. by Standing5(m): 7:35pm On Oct 23, 2015 |
liliian:As for background colour, do you mean the color of the main background should be changed from its default with another image/color? Also, by 'Layout', i believe you want one of the regular java swing layouts. |
Re: I Need Help In Java Programming. by liliian(f): 7:41pm On Oct 23, 2015 |
Standing5: just a well planned layout,colour schemes and borders.Maybe color in the button or so. bolded yes. |
Re: I Need Help In Java Programming. by liliian(f): 7:43pm On Oct 23, 2015 |
Standing5: yes around that.Just like the example the other dude gave on this thread. |
Re: I Need Help In Java Programming. by Standing5(m): 8:01pm On Oct 23, 2015 |
liliian:Example the guy gave lacks Multi-threading. Though he declared 'package Concurrency', he didn't demostrate multiple threads running simultaneously. How soon are you looking to have an answer? I asked b'cos i am having serious keyboard challenge with my laptop currently. |
Re: I Need Help In Java Programming. by liliian(f): 8:33pm On Oct 23, 2015 |
Standing5: By the first week of november. But the assignment is focusing more on concurrency in java swing,designing a java windows interface. |
Re: I Need Help In Java Programming. by Nobody: 6:04am On Oct 24, 2015 |
Writing this would be an issue for me because I have a full time job and many deadlines, however we can achieve this, I will simply break the stages it's not as difficult per se, if you look at the issue individually I think you should focus more first on the GUI as the concurrency part can be easily done, but the UI will require a lot of code. what do you have so far, open a github account and put what you have currently so any of us can pull and make commits. It's easier that way than for us to setup a whole project. We can create a simple JFrame and make use of some Button and Text and Background just to satisfy the requirement of the course. all the best bro put it on Github and share the repo |
Re: I Need Help In Java Programming. by liliian(f): 6:13pm On Oct 24, 2015 |
pcguru1: Thank you,i am a lady . I created a GUI with JLabel,JButton and JTextfield.i will put it up here. |
Re: I Need Help In Java Programming. by liliian(f): 7:20pm On Oct 24, 2015 |
package supercat1; import java.awt.*; import java.awt.event.*; import javax.swing.*; // Using Swing components and containers // A Swing application extends javax.swing.JFrame public class supercat1 extends JFrame { private JTextField tfCount; // Use Swing's JTextField instead of AWT's TextField private int count = 0; public supercat1 () { // Get the content pane of top-level container Jframe // Components are added onto content pane Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JLabel("Counter" ) ) ; tfCount = new JTextField(count + "", 10); tfCount.setEditable(false); tfCount.setHorizontalAlignment(JTextField.RIGHT); cp.add(tfCount); JButton btnCount = new JButton("Count Up" ) ; cp.add(btnCount); JButton btnCountd = new JButton("Count Down" ) ; cp.add(btnCountd); JButton btnCounts = new JButton("Stop" ) ; cp.add(btnCounts); btnCount.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ++count; tfCount.setText(count + "" ); } }); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exit program if Jframe's close-window button clicked setSize(300, 100); setTitle("Supercat Counter" ); setVisible(true); // show it } public static void main(String[] args) { // Recommended to run the GUI construction in // Event Dispatching thread for thread-safet operations SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new supercat1(); // Let the constructor does the job } }); } } This is what i have so far.I need the concurrency and another textfield.What i want top achieve is when i press count up,its start counting up and when i press count down,it starts counting down.then stop to stop the counting. Can I get help?cc:pcguru1,timex4u,standing5 |
Re: I Need Help In Java Programming. by liliian(f): 7:12pm On Oct 26, 2015 |
So no one really on NL in this section,where everyone is a programmer can help?i even offered to pay and still none can try to help? |
Re: I Need Help In Java Programming. by lordZOUGA(m): 8:12pm On Oct 26, 2015 |
liliian:Hello, see https://gist.github.com/anonymous/e835dd43a6effccec79f I modified parts of the code you posted to make that. it uses a timer to update the UI concurrently. I only implemented the count increment part. I think you should be able to complete it. it has not been tested. |
Re: I Need Help In Java Programming. by Nobody: 9:31pm On Oct 26, 2015 |
Re: I Need Help In Java Programming. by liliian(f): 10:58pm On Oct 26, 2015 |
lordZOUGA: I tried with netbeans,but it is not working.There is a mistake here in line 20 and 27. private final Timer mTimer = new Timer(); this is what it's saying in the compiler: Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - constructor Timer in class javax.swing.Timer cannot be applied to given types; Nevertheless i am impress and thankful,just try and see what the problem is.thanks. |
Re: I Need Help In Java Programming. by Nobody: 12:32pm On Oct 27, 2015 |
click the errors and use quickfix to debug the codes . |
Re: I Need Help In Java Programming. by Nobody: 2:52pm On Oct 27, 2015 |
Liliian, this isn't very efficient way to go about the problem, but should give you some clues to the solution. I did a little tweaking of the original code you and lordzouga posted just so it works. Here it is! You could ask for further assistance where needed. |
Re: I Need Help In Java Programming. by MOM1(m): 6:38pm On Oct 27, 2015 |
Does anyone knows how to use the Oracle Virtual Machine? |
Re: I Need Help In Java Programming. by lordZOUGA(m): 8:18pm On Oct 27, 2015 |
NixowL:Thanks for fixing that. I actually don't have the Java framework to test that. All the java code I have ever had to write is for android. Please what would be the most efficient way of doing this? |
Re: I Need Help In Java Programming. by Nobody: 10:39pm On Oct 27, 2015 |
lordZOUGA:You're welcome. What I had in mind might be a little too advanced for OP at this stage. I'd rather let her run away with her imagination. |
Re: I Need Help In Java Programming. by liliian(f): 11:33pm On Oct 27, 2015 |
NixowL: Damn! You are a life saviour. Could you please help with comments in each line so i can understand what you did and also help explain the methods and techniques you used and why? Thank you.I am sending you an email,please you can send me there and we can discuss because you have just made my day. |
Re: I Need Help In Java Programming. by liliian(f): 11:34pm On Oct 27, 2015 |
lordZOUGA: Thank you very much,you really took time to help me. |
Re: I Need Help In Java Programming. by lordZOUGA(m): 12:03am On Oct 28, 2015 |
NixowL:Oh.. Okay. Though I am asking for myself too. We are all here to learn. |
Re: I Need Help In Java Programming. by lordZOUGA(m): 12:12am On Oct 28, 2015 |
liliian:You are welcome. |
Re: I Need Help In Java Programming. by orobogenius: 6:49am On Oct 28, 2015 |
... |
Re: I Need Help In Java Programming. by Nobody: 8:23am On Oct 28, 2015 |
orobogenius: Does this take care of minute milliseconds? Why not use java.util.concurrent.TimeUnit |
Re: I Need Help In Java Programming. by orobogenius: 9:30am On Oct 28, 2015 |
danjumakolo: The TimeUnitin javax.swing.Timerclass is in milliseconds sir. 1 Like |
(1) (Reply)
Phpbrowserbox 4.0 Is Out - Portable Webkit/PHP 7 Combined / My Journey Into Low/no-code Platforms / Is Java The Right Programming Language For Me?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 52 |