Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help..Simple GUI needs help,can not sort out these red lines..

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Help..Simple GUI needs help,can not sort out these red lines..

    //Customer Class
    public class Customer {
    private String name;
    private String address;
    private double balance;
    public Customer(String name, String address, double balance) {
    super();
    this.name = name;
    this.address = address;
    this.balance = balance;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getAddress() {
    return address;
    }
    public void setAddress(String address) {
    this.address = address;
    }
    public double getBalance() {
    return balance;
    }
    public void setBalance(double balance) {
    this.balance = balance;
    }
    @Override
    public String toString() {
    return "Customer [address=" + address + ", balance=" + balance
    + ", name=" + name + "]";
    }



    }


    import java.awt.Frame;
    import java.awt.TextField;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JTextField;

    import net.miginfocom.swing.MigLayout;


    public class CustomerDialog extends JDialog {
    private JLabel nameLabel = new JLabel("Name");
    private JTextField nameTextField = new JTextField(20);
    private JLabel addressLabel = new JLabel("Address");
    private JTextField addressTextField = new JTextField(20);
    private JLabel balanceLabel = new JLabel("Balance");
    private JTextField balanceTextField = new JTextField(20);

    private JButton okButton = new JButton("Ok");
    private JButton cancelButton = new JButton("Cancel");
    private Customer customer;

    public CustomerDialog(Frame owner,boolean modal){
    super(owner,modal);
    this.setLayout(new MigLayout());
    this.add(nameLabel);
    this.add(nameTextField,"wrap");
    this.add(addressLabel);
    this.add(addressTextField,"wrap");
    this.add(balanceLabel);
    this.add(balanceTextField,"wrap paragraph");
    this.add(okButton,"split 2,span 2,tag ok");
    this.add(cancelButton,"tag cancel");

    okButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
    String name = new TextField.getText();
    String address = new TextField.getText();
    String balanceAsString = balanceTextField.getText();
    double balance = Double.parseDouble(balanceAsString);
    customer = new Customer(name,address,balance);
    CustomerDialog.this.setVisible(false);
    }
    });



    }
    public Customer getCustomer()
    {
    return customer;
    }
    }



    import java.util.ArrayList;
    import java.util.List;


    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;

    public class CustomerTableModel extends AbstractTableModel {
    private static final long serialVersionUID = 1L;
    private List<Customer>customers;
    private ArrayList<Customer> customers1 = new ArrayList <Customer> ();

    private CustomerTableModel tableModel = new CustomerTableModel(customers);
    private JTable table = new JTable(tableModel);
    private JScrollPane scrollpane = new JScrollPane(table);

    public CustomerTableModel(List<Customer>customers) {
    this.customers = customers;
    }
    public int getColumnCount() {
    return 3;
    }
    public int getRowCount() {
    return customers.size();
    }
    public Object getValueAt(int rowIndex, int columnIndex) {
    Customer customer = customers.get(rowIndex);
    Object result;
    if(columnIndex == 0){
    result = customer.getName();
    }
    else if(columnIndex == 1){
    result = customer.getAddress();
    }
    else {
    result = customer.getBalance();

    }
    return result;
    }


    }


    import java.awt.List;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;

    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.UIManager;

    import net.miginfocom.swing.MigLayout;


    public class MainWindow extends JFrame {
    List<Customer> customer = new ArrayList<Customer>();
    private JMenuBar mainMenuBar = new JMenuBar();
    private JMenuBar menuBar = new JMenuBar();
    private JMenu customerMenu = new JMenu("Customer");
    private JMenuItem newCustomerItem = new JMenuItem("New..");

    public MainWindow() {
    this.setLayout(new MigLayout());
    this.setJMenuBar(mainMenuBar);
    mainMenuBar.add(customerMenu);
    customerMenu.add(newCustomerItem);


    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
    }
    catch (Exception ignored){

    }

    MainWindow window = new MainWindow();
    window.setDefaultCloseOperation(EXIT_ON_CLOSE);
    window.setLocationRelativeTo(null);
    window.setSize(500,400);
    window.setVisible(true);

    // TODO Auto-generated method stub

    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help..Simple GUI needs help,can not sort out these red lines..

    Please copy the full text of the error messages and paste them here.
    It's hard to see the red lines from here.

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

Similar Threads

  1. How do I sort strings without using the sort method?
    By mjballa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 4th, 2011, 03:27 PM
  2. Collision with drawn lines?
    By SkyAphid in forum The Cafe
    Replies: 3
    Last Post: November 4th, 2011, 05:59 PM
  3. How would you get a JTextArea to know how many lines it had?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 20th, 2011, 07:58 PM
  4. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM
  5. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 10:24 AM