Hi
I'm new to all this programming stuff and have a minor problem with Jbuilders tutorial on The Text Editor (hey you have to start somewhere!!!). It wont compile or run on step 8. Its asking for a }, when I do this in the place it suggests it still won't run. Below is the code - any help would be appreciated - its probably very simple but I cannot find it.
Many thanks
Doug
package texteditor;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Title: Text Editor
* Description:
* Copyright: Copyright (c) 2001
* Company: Java Inc.
* @author D S Blunden
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem5 = new JMenuItem();
JMenuItem jMenuItem6 = new JMenuItem();
JMenuItem jMenuItem7 = new JMenuItem();
JFileChooser jFileChooser1 = new JFileChooser();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon(texteditor.Frame1.class.getResource("openFile.gif");
image2 = new ImageIcon(texteditor.Frame1.class.getResource("closeFile.gif");
image3 = new ImageIcon(texteditor.Frame1.class.getResource("help.gif");
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title"
statusBar.setText(" "
jMenuFile.setText("File"
jMenuFileExit.setText("Exit"
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuHelp.setText("Help"
jMenuHelpAbout.setText("About"
jMenuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuHelpAbout_actionPerformed(e);
}
});
jButton1.setIcon(image1);
jButton1.setToolTipText("Open File"
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File"
jButton3.setIcon(image3);
jButton3.setToolTipText("Help"
jTextArea1.setLineWrap(true);
jTextArea1.setWrapStyleWord(true);
jMenuItem1.setText("New"
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
});
jMenuItem2.setText("Open"
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
});
jMenuItem3.setText("Save"
jMenuItem4.setText("Save As"
jMenu1.setText("Edit"
jMenuItem5.setText("Font"
jMenuItem6.setText("Foreground Colour"
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem6_actionPerformed(e);
}
});
jMenuItem7.setText("Background Color"
jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem7_actionPerformed(e);
}
});
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jFileChooser1_actionPerformed(e);
}
});
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jMenuFile.add(jMenuItem1);
jMenuFile.add(jMenuItem2);
jMenuFile.addSeparator();
jMenuFile.add(jMenuItem3);
jMenuFile.add(jMenuItem4);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jToolBar, BorderLayout.NORTH);
jMenu1.add(jMenuItem5);
jMenu1.add(jMenuItem6);
jMenu1.add(jMenuItem7);
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Frame1_AboutBox dlg = new Frame1_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jMenuItem6_actionPerformed(ActionEvent e) {
Color color = JColorChooser.showDialog(this,"Foreground Color",jTextArea1.getForeground());
if (color != null)
jTextArea1.setForeground(color);
this.repaint();
}
void jMenuItem7_actionPerformed(ActionEvent e) {
Color color = JColorChooser.showDialog(this,"Background Color",jTextArea1.getBackground());
if (color != null)
jTextArea1.setBackground(color);
this.repaint();
}
void jMenuItem1_actionPerformed(ActionEvent e) {
jTextArea1.setText(""
}
void jMenuItem2_actionPerformed(ActionEvent e) {
if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) {
statusBar.setText("Opened" +jFileChooser1.getSelectedFile().getPath());
}
}
I'm new to all this programming stuff and have a minor problem with Jbuilders tutorial on The Text Editor (hey you have to start somewhere!!!). It wont compile or run on step 8. Its asking for a }, when I do this in the place it suggests it still won't run. Below is the code - any help would be appreciated - its probably very simple but I cannot find it.
Many thanks
Doug
package texteditor;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Title: Text Editor
* Description:
* Copyright: Copyright (c) 2001
* Company: Java Inc.
* @author D S Blunden
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenuItem jMenuItem4 = new JMenuItem();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem5 = new JMenuItem();
JMenuItem jMenuItem6 = new JMenuItem();
JMenuItem jMenuItem7 = new JMenuItem();
JFileChooser jFileChooser1 = new JFileChooser();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon(texteditor.Frame1.class.getResource("openFile.gif");
image2 = new ImageIcon(texteditor.Frame1.class.getResource("closeFile.gif");
image3 = new ImageIcon(texteditor.Frame1.class.getResource("help.gif");
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title"
statusBar.setText(" "
jMenuFile.setText("File"
jMenuFileExit.setText("Exit"
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuHelp.setText("Help"
jMenuHelpAbout.setText("About"
jMenuHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuHelpAbout_actionPerformed(e);
}
});
jButton1.setIcon(image1);
jButton1.setToolTipText("Open File"
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File"
jButton3.setIcon(image3);
jButton3.setToolTipText("Help"
jTextArea1.setLineWrap(true);
jTextArea1.setWrapStyleWord(true);
jMenuItem1.setText("New"
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
});
jMenuItem2.setText("Open"
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
});
jMenuItem3.setText("Save"
jMenuItem4.setText("Save As"
jMenu1.setText("Edit"
jMenuItem5.setText("Font"
jMenuItem6.setText("Foreground Colour"
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem6_actionPerformed(e);
}
});
jMenuItem7.setText("Background Color"
jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem7_actionPerformed(e);
}
});
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jFileChooser1_actionPerformed(e);
}
});
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jMenuFile.add(jMenuItem1);
jMenuFile.add(jMenuItem2);
jMenuFile.addSeparator();
jMenuFile.add(jMenuItem3);
jMenuFile.add(jMenuItem4);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jToolBar, BorderLayout.NORTH);
jMenu1.add(jMenuItem5);
jMenu1.add(jMenuItem6);
jMenu1.add(jMenuItem7);
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Frame1_AboutBox dlg = new Frame1_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jMenuItem6_actionPerformed(ActionEvent e) {
Color color = JColorChooser.showDialog(this,"Foreground Color",jTextArea1.getForeground());
if (color != null)
jTextArea1.setForeground(color);
this.repaint();
}
void jMenuItem7_actionPerformed(ActionEvent e) {
Color color = JColorChooser.showDialog(this,"Background Color",jTextArea1.getBackground());
if (color != null)
jTextArea1.setBackground(color);
this.repaint();
}
void jMenuItem1_actionPerformed(ActionEvent e) {
jTextArea1.setText(""
}
void jMenuItem2_actionPerformed(ActionEvent e) {
if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) {
statusBar.setText("Opened" +jFileChooser1.getSelectedFile().getPath());
}
}