Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Flag Bad Post calls a post to the attention of the moderators for things like spam, egregious rule violations, misplaced posts (ie.e wrong forum), etc.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

*shhh* a mod just showed up.... :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Already flagged "Bad Post".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, most of the site is for technical discussions and problem solving. The "lounge" forums are just informal places for idle chatter. There certainly are not any "adult-only" type areas on the site, so beyond just chatting with people there isn't really much else to it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Another loop inside that one on

while( tokens.hasMoreTokens() )

is all you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, no I didn't notice - I saw a wall of code with no question and didn't bother beyond that point :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That part is for you to figure out. Methods cannot be defined within other methods, so each method block must be defined separately within the class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just like you end any other method - with a brace.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You haven't ended the main() method block. Until you do that you can't start a new method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well yes, if all you want to do is pipe your program output stream to a file that is fine. If you need to have any greater control over what gets written to the file you'll need to use the FileWriter.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't at this point.

The "EmailSender" class has no methods to interact with and is just a series of commands in main(). You'll have to re-write "EmailSender" to be a class with methods to set the parameters for the email and a send() method to send it.

The interface would then pass the info collected to the appropriate methods on the EmailSender and the "Send" button listener would invoke the EmailSender.send() message.

You have a bit of work ahead of you before they can be "combined".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Which method are you wanting to pass an object to? "idMethod" is getting a no-arg method and "getMethod" is getting this method getInstance(String) with this line

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{Class.forName("java.lang.String")});

. If you need getInstance(Object) the you need to use

Method getMethod = Class.forName(ClassName).getMethod("getInstance", new Class[]{java.lang.Object.class});

Your question is not very clear, so if that is not what you were asking you will need to clarify it a bit more.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, as you have it written it would just save the single line read from the console to that file. You are not reading anything from your threads and currently those threads don't have any output anyway, so there seems little to save at this point.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are pretty close. The errors are because you still have mismatched braces on the loop blocks. You left the do() statement in, which is messing up your while() block. Walk through the flow of that while() block and you'll see that you need to prompt for another customer name at the end of it so the sentinel while() test can evaluate whether you want to continue or stop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

After you have computed the quarterly totals and before you display the differences seems like a pretty good candidate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use this constructor for your FileWriter to append to the file instead of overwriting it: FileWriter.FileWriter(java.lang.String,boolean)

You will also need to change \\ file to output or save to to // file to output or save to if you want that to compile - wrong slashes for an inline comment.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, so now what problems are you having? Reposting your code with no question is not getting anywhere. No one is going to start fixing things in it for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, unless you find a reason to speed up that array initialization, that will certainly work just fine. My point was that the identity matrix is constant for a given matrix size and could be cached for reuse instead of creating it each time the inversion routine is called.

If you are coding all of your matrix operations from scratch, you may want to consider using a package like Apache Commons Math.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is no guaranteed return path because your return is within a conditional statement. This means that when your if() test is false the function has no return value - and the compiler won't allow that. You need a return outside of the if statement as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That line is actually the entirety of this statement

b[index[j]][k] = b[index[j]][k].subtract( a[index[j]][i].multiply (b[index[i]][k]));

You are performing an operation on a value in b[][], but you haven't initialized all of the elements in b[][]. You have only initialized the diagonal of that matrix here

for (int i=0; i<n; ++i) b[i][i] = new BigDecimal("1");

The double array used previously had default values of 0, but with the BigDecimal version you have nulls in all but the diagonal. You need to first initialize the values in b[][] to valid BigDecimal instances for 0.

If your matrix sizes are constant in size, you may be able to make that initialization easier and faster with System.arraycopy() from a single BigDecimal(0) template array, but then that is only a consideration after you get the thing working properly first.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

DecimalFormat("#.##") will show up to 2 decimal places if applicable. If you want to always show 2 digits after the decimal use DecimalFormat("#.00") Edit: Just noticed, but you are not even using the DecimalFormat you created. You need to use that instance to format your numbers like so

System.out.println("The maxiumum score is " + twoDigits.format(max_score) );

(ditch the 8-space tab indent too - it's just painful to read)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The row must be added to the TableModel, not the JTable as you are attempting. In particular, that method is provided by DefaultTableModel and is not in the general TableModel interface, so you will either need to keep a reference to the DefaultTableModel that you are creating

DefaultTableModel tableModel = new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null}
},
new String [] {
"Kode group", "Nama group"
});  // plus all of your other extension code of course
tblGroupAnggaran.setModel(tableModel);

(though that reference will actually need to be an instance-level reference, not local as in this example) or get the model from the table and cast it to DefaultTableModel

((DefaultTableModel)tblGroupAnggaran.getModel()).addRow(data);

I would also recommend making your DefaultTableModel extension it's own separate inner class. It would be much easier to read and maintain over the anonymous inner class you are currently using.

Kusno commented: Clear explanations +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

wat is import?? how?? i jz beginner in java...

Then obviously you didn't copy all of the appropriate code from wherever you copied this routine. You need to specify "import <package>.<class>;" for each of those classes that you are using.

Honestly, if you don't know what an import is then you have no hope of just jumping in to modify all of that code. You need to start with some basics first. See the "Starting Java" Read Me post at the top of the forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It would help a lot if you either used [code=java], which would place line numbers in the listing or highlighted the line number in your code, since most can't just quickly pick out line 174. Here is that code with line numbers:

I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

import java.util.Scanner;


public class Vehicle{
protected int hp;
protected int mileage;
protected int year;
public String make;
public String model;

Vehicle(){
hp = 0;
mileage = 0;
year = 0;
}

public void Set(int inputhp, int inputmileage, int inputyear){
hp = inputhp;
mileage = inputmileage;
year = inputyear;
}

//public static void Print(int hp, int mileage, int year){
/*
public  void Print(Vehicle carinfo){

System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
"\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
}
*/



public  void Print(){

System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
"\n Make: " + make + "\n Model: " + model);
}

/*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){

int count = 0;
for(i = 0; i < 1; i++){

if(yearcheck = carinfo[i].year){
System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
count++;
										}
												}
												if(count = 0){
												System.out.println("There were no matches of that year");
												} …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then you need to make sure that the BufferedWriter is being created correctly and the "myList" has been initialized by the point you are calling that loop.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

P.S. Sorry for the (I don't know how to use that)... :(

Just place [code] before and [/code] after your code, or you can highlight the code and click the little toolbar button to "Wrap CODE tags around selected tags" (the one that shows #). It will preserve the tab and space formatting and make it much easier to read.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You said that you had problems using the double constructor, but that code is passing a BigDecimal. If you just need to negate the sum, why not use the method BigDecimal.negate()? Alternately you could multiply(-1.0). The api doc is your best friend for things like this.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See the resources outlined in the Read Me post at the top of this forum. There is a lot of info there to get you started.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course not! :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the string literal "-sum" will never be parsed as a number because "sum" is just a string there - not a variable.

What problem was the negative sign causing? This code seems to work just fine

double value = 2.345;
BigDecimal bdValue = new BigDecimal(-value);
System.out.println(bdValue);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course, this is exactly what a Dialog is for...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at this example on disallowing edits: http://exampledepot.com/egs/javax.swing.table/NoEdit.html
The signature of the method that they are overriding should give you a pretty good idea on how to disallow editing on any particular row or column.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The stack trace is showing the error occurring in sigmoidActivationFunction

at newtonsMethod1.sigmoidActivationFunction(newtonsMethod1.java:118)

and if you look at the constructor you are using for BigDecimal there the error should be pretty clear. I doubt what you wrote there can be formatted as a number.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because your toString() method is not returning a string, it's just printing stuff out to the console. It needs to build a string and return it.

Also, after 18 posts, you should learn to use [code] [/code] tags around code that you post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If the assignment is to implement an insertion sort on a linked list, you need to read your notes on what an insertion sort is. Inserting into a list is not an insertion sort. If that is not the assignment then you need to rephrase the question to clarify what you need to accomplish.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you figure that future employers are always going to give you an example of the system they want you to implement and walk you through how to do it? You need to take some initiative and research whatever topic you undertake.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Of course it's endless - because you are not ever reading the next line. The loop that I wrote reads the line into "line" each iteration of the loop and checks it against null. Yours calls readLine() one time and keeps looping while "line" is not null - so the loop is either endless or never executes in the first place. If the syntax of the loop I wrote it confusing you, try it like this instead

// I can only assume this method returns a BufferedReader
BufferedReader reader = BbmReader.getFileReader("input.txt");
String line = reader.readLine();
while (line != null){
    StringTokenizer tokens = new StringTokenizer(line," ");
    System.out.println(tokens.nextToken());
    // you still need another loop here to read the rest of the tokens
    ...
    line = reader.readLine();
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It certainly will if you use the loop as I indicated. Get the reader one time and then use that loop to read lines from it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That is an insert into a list- not an insertion sort - and you are comparing the item to itself, which is probably less than useful.

The insertion sort should do an in-place sort of an existing list.

If all you need to do is insert into an existing sorted list then simply walk the list until you find the correct place and insert the new item.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to have the read in a loop like so

while ((line = reader.readLine()) != null){
    StringTokenizer tokenizer = new StringTokenizer(line," ");
    // do stuff
}

I have no idea where the "BbmReader" class comes from, so I can't speak to any specifics on that, but the general loop should work the same.

By the way, StringTokenizer is an old legacy class and you should generally use String.split() instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's the same principle as with an array but you update the list pointers instead of shifting the array elements.

If you need more specific answers, you need to ask more specific questions. No one here is going to write the sort for your homework assignment, so post the code you have and what questions you have about it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You actually need to add the data to the TableModel. You can either implement the TabelModel yourself against your existing data (whether that is in an array, list, or whatever) or create an instance of DefaultTableModel with your data. Read through these for more info and examples:
http://www2.sys-con.com/ITSG/VirtualCD_Spring05/Java/archives/0405/hatmaker/index.html
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can do it with a custom cell renderer like so:

class CustomIconRenderer extends DefaultTreeCellRenderer {
    ImageIcon defaultIcon;
    ImageIcon specialIcon;

    public CustomIconRenderer() {
        defaultIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/defaultIcon.gif"));
        specialIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/specialIcon.gif"));
    }

    public Component getTreeCellRendererComponent(JTree tree,
      Object value,boolean sel,boolean expanded,boolean leaf,
      int row,boolean hasFocus) {

        super.getTreeCellRendererComponent(tree, value, sel, 
          expanded, leaf, row, hasFocus);

        Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
        // check whatever you need to on the node user object
        if (((WhateverNodeObjectClass)nodeObj).someProperty) {
            setIcon(specialIcon);
        } else {
            setIcon(defaultIcon);
        } 
        return this;
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use "Case Else":

Select Case Me.Text1.Text
    Case 1
        MsgBox ("U Entered 1")
    Case 2
        MsgBox ("U entered 2")
    Case 3
        MsgBox ("u entered 3")
    Case Else
        MsgBox ("Default")
End Select
sujimon commented: useful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Each panel can keep all of it's layout setup completely internal (and should). The code that puts together the main frame should place the panels wherever they need to go.

Edit: Fireworks panel can still have as many internal panels as it wants to group components together. The main frame can still just treat it as a single component. If FireworksPanel has two internal panels, one for the screen and one for buttons, that won't affect the main frame at all. You don't have to put each piece into the frame - panels can have panels within panels within panels ad nauseum, so don't think each piece has to go into the top level container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Maybe something along these lines would work for you

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.*;

public class FrameExample extends JFrame {

    JPanel panNorth;
    JPanel panSouth;
    JPanel panCenter;

    public FrameExample() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setLayout(new BorderLayout());

        // set up top panel
        panNorth = new JPanel();
        panNorth.setLayout(new FlowLayout());
        panNorth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        JLabel lblUpper = new JLabel("Upper Panel");
        panNorth.add(lblUpper);
        add(panNorth, BorderLayout.NORTH);

        // set up center panel
        panCenter = new JPanel();
        panCenter.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        panCenter.setLayout(new BorderLayout());
        JLabel lblMiddle = new JLabel("Middle thing");
        lblMiddle.setHorizontalAlignment(JLabel.CENTER);
        panCenter.add(lblMiddle, BorderLayout.CENTER);
        add(panCenter);

        // set up bottom panel
        panSouth = new JPanel();
        panSouth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
        panSouth.setLayout(new FlowLayout());
        JButton btnFirst = new JButton("Button 1");
        // if preferred size is not set then the button will size to fit the text on it
        btnFirst.setPreferredSize(new Dimension(100,18));
        panSouth.add(btnFirst);
        JButton btnSecond = new JButton("Button 2");
        btnSecond.setPreferredSize(new Dimension(100,18));
        panSouth.add(btnSecond);
        add(panSouth, BorderLayout.SOUTH);

        setSize(300, 300);
        setVisible(true);
    }

    public static void main(String args[]) {
        new FrameExample();
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can probably use a BorderLayout for the main frame with your main panel in CENTER and a button panel in SOUTH. The button panel could use FlowLayout or GridLayout perhaps. Neither of those is too complex.

GridBagLayout would be more flexible, but it can take a little work to get comfortable with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This tutorial has examples of working with the available layout managers: http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html