|
lol yea the teacher wants equals(Polynominal p) so is my way right or wrong?
|
|
|
|
|
looks good at a first glance - needs some fixes (read the comments).
How do you programm? Do you use a IDE like Eclipse or Netbeans?
regards Torsten
I never finish anyth...
|
|
|
|
|
Accessing private members that way? at least bad style.
my suggestion:
public Polynomial(Polynomial p)
{
coeff = p.getCoeff();
}
regards Torsten
I never finish anyth...
|
|
|
|
|
There is no method getCoeff() , just getCoeff(int) .
Seriously, I don't think accessing member variables in a constructor is necessarily bad, but I guess OP could go for the 'collapse all constructors into one' approach:
public Polynomial(Polynomial p)
{
this(p.getCoeff(0),
p.getCoeff(1),
p.getCoeff(2),
p.getCoeff(3),
p.getCoeff(4));
}
public Polynomial()
{
this(0, 0, 0, 0, 0);
}
public Polynomial(int c0, int c1, int c2, int c3, int c4)
{
this.coeff = new int[5];
this.coeff[0] = c0;
this.coeff[1] = c1;
this.coeff[2] = c2;
this.coeff[3] = c3;
this.coeff[4] = c4;
}
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
TorstenH. wrote: Please use decent Hungarian Code conventions:
Without opening a can of worms as to the pros and cons of Hungarian notation, I wouldn't teach a Java newbie to use Hungarian for the simple reason that most Java coders do not use it so it will just confuse people. Sun published a set of standards years ago which still pretty much form the basis of 99.9% of java shops' coding conventions in the real world, so I would advise newbies to go and read that and follow it.
|
|
|
|
|
I know that most people do not use Hungarian Code Conventions for their code. But I think it makes programming especially for students simpler. Using clear naming for the variables and methods makes it much easier to deal with them.
regards Torsten
I never finish anyth...
|
|
|
|
|
As I said, I don't really want to get into the pros and cons of Hungarian notation. It's one of those religious discussions that usually descends into a pointless to-and-fro "my dad's bigger than your dad" kind of argument. It ranks somewhere alongside the question of whether opening braces should be placed on the same line or the following line.
|
|
|
|
|
naaa, it's not that kind of discussion.
I always see beginners using non-unique names for their variables and members like "b1, b2, b3, ..". It get's worse when it comes to list and labels, which are often named the same way: "l1, l2, l3, ...".
It'S so easy to get that cleared up! One can mess around when he's a pro and does code no one cares of. But as soon as a second person has to deal with the code, one should take a seconds time to think about.
EDIT: Check his new thread: http://www.codeproject.com/Messages/4032381/Polynomial-class-need-some-assistance-with-it.aspx[^]
He's using an int "coeff" in his main function and has the member Array[] "coeff" in the object he's dealing with. Technically allowed - but not helping at all.
regards Torsten
I never finish anyth...
|
|
|
|
|
Hello again I am creating again a new app in java which can animate images. I have problem with JRadionButton if I am going to select another one it marked with a dot and if I select another one it also marked with a dot without removing the pass which I had selected.
Here's my code
package star;
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
public class StarAnimate extends JFrame implements ItemListener {
JPanel panel = new JPanel();
JRadioButton btnBoard1 = new JRadioButton("Board 1", true);
JRadioButton btnBoard2 = new JRadioButton("Board 2");
JRadioButton btnBoard3 = new JRadioButton("Board 3");
Board board1 = new Board();
Board2 board2 = new Board2();
Board3 board3 = new Board3();
public StarAnimate() {
init();
}
private void init() {
btnBoard1.setBounds(5, 10, 100, 30);
btnBoard1.setBackground(Color.red);
btnBoard1.addItemListener(this);
btnBoard2.setBounds(5, 40, 100, 30);
btnBoard2.setBackground(Color.red);
btnBoard2.addItemListener(this);
btnBoard3.setBounds(5, 70, 100, 30);
btnBoard3.setBackground(Color.red);
btnBoard3.addItemListener(this);
panel.setLayout(null);
panel.setBounds(0, 0, 160, 540);
panel.setBackground(Color.red);
panel.add(btnBoard1);
panel.add(btnBoard2);
panel.add(btnBoard3);
this.add(panel);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(560, 540);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.setTitle("Star Animation");
this.setResizable(true);
this.setVisible(true);
}
public static void main(String[] args) {
StarAnimate star = new StarAnimate();
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() == btnBoard1) {
this.add(board1);
this.remove(board2);
this.remove(board3);
}
if (e.getSource() == btnBoard2) {
this.add(board2);
this.remove(board1);
this.remove(board3);
}
if (e.getSource() == btnBoard3) {
this.add(board3);
this.remove(board2);
this.remove(board1);
}
}
}
|
|
|
|
|
Add your JRadioButton into a JRadioButtonGroup
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
Lol this is it thanks. Anyway its just ButtonGroup not JRadioButtonGroup.
|
|
|
|
|
flashery wrote: Anyway its just ButtonGroup not JRadioButtonGroup.
Sorry about that, my brain's currently running in safe-mode (ie. debugging some VB apps)
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
|
|
|
Hello again, its been a while since I post here I am making a Timer application in java. Which shutdown the PC on specified time.
My problem is it is showing a warning
Note: C:\Users\flashery\Documents\NetBeansProjects\Timer\src\MainTimer.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
How do I do this recompiling?
Can someone give me a hint on this thing..
|
|
|
|
|
Just add that option to your javac command, or project options in NetBeans. Alternatively find the deprecated method you are calling and change it for the latest version; the documentation will tell you how.
BTW the link in your title links back here.
|
|
|
|
|
Thanks Richard MacCutchan it really helps me.
For those who don't know here's the details
It's just for NetBeans IDE 7.0.1 I don't know how to do it on other IDE.
1. Right click on your project you can see it on the left side of the IDE project tab and select properties.
2. In the project property window just click compiling on the left side of the window.
3. Find this option after clicking the compiling "Additional Compiling Options:" it is located on the lowest side and add your compiling option in my case I add this on the textbox.
-Xlint:deprecation
4. Click OK and your done.
5. Try debugging your project and your will see a message like this on the output option of debugging.
C:\Users\flashery\Documents\NetBeansProjects\Timer\src\MainTimer.java:93: warning: [deprecation] disable() in javax.swing.JComponent has been deprecated
cmbTime.disable();
C:\Users\flashery\Documents\NetBeansProjects\Timer\src\MainTimer.java:190: warning: [deprecation] disable() in javax.swing.JComponent has been deprecated
cmbTime.disable();
C:\Users\flashery\Documents\NetBeansProjects\Timer\src\MainTimer.java:206: warning: [deprecation] enable() in javax.swing.JComponent has been deprecated
cmbTime.enable();
Hope this helps. I really google it and there's no detailed info on how to do it. I am thankful to Richard MacCutchan for saying its on the project option.
|
|
|
|
|
I am providing an interface to one of my products as a 'C' language DLL, compiled using Microsoft Visual Studio 2008. The interface may be used in a Java application. I don't know Java, so I could use some guidance on things I need to do in my DLL to make it as easy to use as possible.
The functions in my DLL only take arguments in the form of 32-bit signed integers, pointers to integers, and constant UNICODE (const wchar_t* ) strings, and return 32-bit signed integers. I would like to let them use callback functions with similar signatures. The target environment could be Windows XP, Windows 7 (32-bit), or Windows 7 (64-bit).
I've done some preliminary reading, and it appears that Java Native Access[^] (JNA) is the easiest way for a Java client to use functions in a DLL like this.
Are there any gotchas I need to be aware of?
Software Zen: delete this;
|
|
|
|
|
Personally I would fully encapsulate the DLL.
Where I've done this before, I have used a pure interface class mapping to the dll, but kept it package level.
Then create a public class that accesses the DLL.
This gives future proofing, for example if you need to move to a new version of windows and the API [shock! horror!] changes you only need to update the internal DLL interface and not the entire project.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Hmm. I should have made this clearer.
I'm mainly concerned about how to do things in the functions the DLL provides:
Are const wchar_t * strings okay? Or should I use const char * , and insist on UTF-8 encoding (these are things like file paths)?
I assume returning values via int * arguments will work?
Can I use callback functions? I have asynchronous events that I would like to use a callback function for. The caller would pass the DLL a function pointer, which I would then call as needed for an event.
Software Zen: delete this;
|
|
|
|
|
|
Very Richard. I had seen the JNA, but hadn't read too much about it. Thanks!
Software Zen: delete this;
|
|
|
|
|
Thanks; I have only used JNI myself, and although it's a bit of a learning curve it works well. From my reading of the JNA documentation that may be an easier option.
|
|
|
|
|
I don't actually want to give the users of this DLL the Java required to use it. They have a pronounced case of "Not Invented Here" syndrome. I'm just trying to reduce the amount of grief I get from them.
Software Zen: delete this;
|
|
|
|