Link to home
Start Free TrialLog in
Avatar of RayGun
RayGun

asked on

Pretty easy for you, very annoying for me. Some help please

This is part of the code:

import java.applet.Applet;
import java.applet.*;
import javax.swing.*;
//import java.awt.Graphics;
//import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.text.*;
import java.util.*;


public class ArticleInterface extends Applet implements ActionListener, ItemListener
{
//globale variabler UI
private Button btHeadline;                   
private Button btPictureText;             
private Button btText;                   
private Button btSource;            
private Button btDate;                  
private TextField tfHeadline;             
private TextArea taPictureText;
private TextArea taText;                   
private TextField tfSource;                  
private String Headline;                  
private String PictureText;            
private String Text;                         
private Button btShow;                  
private TextField tfFilename;            
private ImageCanvas c;                        
private Checkbox chkPri;                  
//Globale variabler JDBC
String databaseURL, databaseName;
Connection con;
public static Statement stmt;
public static ResultSet rs;
public static ResultSetMetaData rsmd;

private String username;
private String password;

  public void init()
  {
      //setter farger og layout for applet
      setBackground(Color.lightGray);
      setLayout(null);

      //oppretter et grafikkpanel
      Panel p = new Panel();


//oppretter grafikkobjekter til panelet
//Tekstdel
btHeadline = new Button("Skriv Overskrift");
btPictureText = new Button("Skriv Intro");
btText = new Button("Skriv Brødtekst");
btSource = new Button("Kilde");
btDate = new Button("Sett dato");
tfHeadline = new TextField(20);
tfSource = new TextField(20);
taPictureText = new TextArea("",5,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
      taText = new TextArea("",5,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
      chkPri = new Checkbox("Prioritert");

//oppretter fonter
Font fontHeadLine = new Font("Areal", Font.BOLD, 20);
Font fontPictureText = new Font("Areal", Font.BOLD, 12);

//Bildedel
btShow = new Button("Vis Bilde");
tfFilename = new TextField(20);
c = new ImageCanvas();


//plasserer grafikkobjekter til panelet
//knapper
p.add(btHeadline);
btHeadline.setBounds(50,50,100,30);

p.add(btPictureText);
btPictureText.setBounds(50,150,100,30);

p.add(btText);
btText.setBounds(50,380,100,30);

p.add(btSource);
btSource.setBounds(50,610,100,30);

//tekstfelt
p.add(tfHeadline);
tfHeadline.setBounds(250,50,200,30);
tfHeadline.setFont(fontHeadLine);

p.add(taPictureText);
taPictureText.setBounds(250,150,200,200);
taPictureText.setFont(fontPictureText);

p.add(taText);
taText.setBounds(250,380,200,200);

p.add(tfSource);
tfSource.setBounds(250,610,200,30);
//Bildedel
p.add(c);
c.setBackground(Color.gray);
c.setBounds(600,50,180,200);

p.add(btShow);
btShow.setBounds(600,300,100,30);
p.add(tfFilename);
tfFilename.setBounds(750,300,200,30);

p.add(btDate);
btDate.setBounds(600,360,100,30);
//Checkboxer
p.add(chkPri);
chkPri.setBounds(600,420,100,30);



//plasserer panelet i framen uten layout
add(p);
p.setLayout(null);
p.setBounds(0,0,1024,768);



//initialiserer listener
btHeadline.addActionListener(this);
btPictureText.addActionListener(this);
btText.addActionListener(this);
btShow.addActionListener(this);
btDate.addActionListener(this);
tfFilename.addActionListener(this);
chkPri.addItemListener(this);
  }

//ActionEvent handler
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
if ((e.getSource() instanceof Button) || (e.getSource() instanceof TextField))
{
if (actionCommand.equals("Skriv Overskrift"))
{
                  
      Headline = tfHeadline.getText();
      System.out.println(Headline);
}
else if (actionCommand.equals("Skriv Bildetekst"))
{
//setter fonter,linjeskift,størrelse
PictureText = taPictureText.getText();

}
else if (actionCommand.equals("Skriv Artikkel"))
            {
//setter fonter,linjeskift,størrelse
      Text = taText.getText();
            }
else if (actionCommand.equals("Sett Dato"))
            {
//set date
Date currentDate = new Date();
DateFormat fmt = getDateInstance(Locale.SHORT);
                                             //ERROR!!!!!
String formatert = fmt.format(currentDate);

            }

else if (actionCommand.equals("Vis Bilde") || (e.getSource() instanceof TextField))
            {
                  displayImage();
            }

        }

      }
public void ItemStateChange(ItemEvent e)
{
if (e.getSource() instanceof Checkbox)
{
boolean b = chkPri.getState();      //sjekker om sjekkboks er satt
if (b = true)
System.out.println("1");
else
System.out.println("0");
            }
      }

When i run this code i get two errors:
1.
ArticleInterface should be declared abstract; it does not define itemStateChanged(java.awt.event.ItemEvent) in ArticleInterface

2.
//The second error i get from this code snippet. It cannot resolve symbol Date in the first line....
Date currentDate = new Date();
DateFormat fmt = getDateInstance(Locale.SHORT);                                          
String formatert = fmt.format(currentDate);

Please help.


Avatar of girionis
girionis
Flag of Greece image

>1.
ArticleInterface should be declared abstract; it does not define itemStateChanged(java.awt.event.ItemEvent) in ArticleInterface

  Since you implement interfaces you need to implement all of their methdos. Just add the following in your code:

public void itemStateChanged(java.awt.event.ItemEvent ie) {}

> 2.
//The second error i get from this code snippet. It cannot resolve symbol Date in the first line....

  Import it by using: import java.util.Date;
Avatar of Venci75
Venci75

there are two Date classes:
java.util.Date
and
java.sql.Date

you must specify which one you want:
java.util.Date currentDate = new java.util.Date();
You had implemented the method but missed out 'd' in itemStateChanged(ItemEvent e).
> You had implemented the method but missed out 'd' in itemStateChanged(ItemEvent e).

  So he didn't implement the method after all :-)

here i have solved above two errors:
-----------------------------------

import java.applet.Applet;
import java.applet.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.text.*;
import java.util.*;


public class ArticleInterface extends Applet implements ActionListener, ItemListener
{
//globale variabler UI
private Button btHeadline;                
private Button btPictureText;          
private Button btText;                
private Button btSource;          
private Button btDate;              
private TextField tfHeadline;          
private TextArea taPictureText;
private TextArea taText;                
private TextField tfSource;              
private String Headline;              
private String PictureText;          
private String Text;                    
private Button btShow;              
private TextField tfFilename;          
private ImageCanvas c;                    
//private ImageCanvas c;                    
private Checkbox chkPri;              
//Globale variabler JDBC
String databaseURL, databaseName;
Connection con;
public static Statement stmt;
public static ResultSet rs;
public static ResultSetMetaData rsmd;

private String username;
private String password;

 public void init()
 {
     //setter farger og layout for applet
     setBackground(Color.lightGray);
     setLayout(null);

     //oppretter et grafikkpanel
     Panel p = new Panel();


//oppretter grafikkobjekter til panelet
//Tekstdel
btHeadline = new Button("Skriv Overskrift");
btPictureText = new Button("Skriv Intro");
btText = new Button("Skriv Brxdtekst");
btSource = new Button("Kilde");
btDate = new Button("Sett dato");
tfHeadline = new TextField(20);
tfSource = new TextField(20);
taPictureText = new TextArea("",5,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
     taText = new TextArea("",5,10,TextArea.SCROLLBARS_VERTICAL_ONLY);
     chkPri = new Checkbox("Prioritert");

//oppretter fonter
Font fontHeadLine = new Font("Areal", Font.BOLD, 20);
Font fontPictureText = new Font("Areal", Font.BOLD, 12);

//Bildedel
btShow = new Button("Vis Bilde");
tfFilename = new TextField(20);
c = new ImageCanvas();


//plasserer grafikkobjekter til panelet
//knapper
p.add(btHeadline);
btHeadline.setBounds(50,50,100,30);

p.add(btPictureText);
btPictureText.setBounds(50,150,100,30);

p.add(btText);
btText.setBounds(50,380,100,30);

p.add(btSource);
btSource.setBounds(50,610,100,30);

//tekstfelt
p.add(tfHeadline);
tfHeadline.setBounds(250,50,200,30);
tfHeadline.setFont(fontHeadLine);

p.add(taPictureText);
taPictureText.setBounds(250,150,200,200);
taPictureText.setFont(fontPictureText);

p.add(taText);
taText.setBounds(250,380,200,200);

p.add(tfSource);
tfSource.setBounds(250,610,200,30);
//Bildedel
p.add(c);
c.setBackground(Color.gray);
c.setBounds(600,50,180,200);

p.add(btShow);
btShow.setBounds(600,300,100,30);
p.add(tfFilename);
tfFilename.setBounds(750,300,200,30);

p.add(btDate);
btDate.setBounds(600,360,100,30);
//Checkboxer
p.add(chkPri);
chkPri.setBounds(600,420,100,30);



//plasserer panelet i framen uten layout
add(p);
p.setLayout(null);
p.setBounds(0,0,1024,768);



//initialiserer listener
btHeadline.addActionListener(this);
btPictureText.addActionListener(this);
btText.addActionListener(this);
btShow.addActionListener(this);
btDate.addActionListener(this);
tfFilename.addActionListener(this);
chkPri.addItemListener(this);
 }

//ActionEvent handler
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
if ((e.getSource() instanceof Button) || (e.getSource() instanceof TextField))
{
if (actionCommand.equals("Skriv Overskrift"))
{
               
     Headline = tfHeadline.getText();
     System.out.println(Headline);
}
else if (actionCommand.equals("Skriv Bildetekst"))
{
//setter fonter,linjeskift,stxrrelse
PictureText = taPictureText.getText();

}
else if (actionCommand.equals("Skriv Artikkel"))
          {
//setter fonter,linjeskift,stxrrelse
     Text = taText.getText();
          }
else if (actionCommand.equals("Sett Dato"))
          {
//set date
java.util.Date currentDate = new java.util.Date();
//DateFormat fmt = getDateInstance(Locale.US);
                                            //ERROR!!!!!
SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy");                                            
String formatert = fmt.format(currentDate);

          }

else if (actionCommand.equals("Vis Bilde") || (e.getSource() instanceof TextField))
          {
               displayImage();
          }

       }

     }
public void itemStateChanged(ItemEvent e)
{
      if (e.getSource() instanceof Checkbox)
      {
            boolean b = chkPri.getState();     //sjekker om sjekkboks er satt
            if (b = true)
                  System.out.println("1");
            else
                  System.out.println("0");
  }
}

}//end of class


Avatar of RayGun

ASKER

You had implemented the method but missed out 'd' in itemStateChanged(ItemEvent e).

You were right about the 'd', but adding it did not solve the problem.
Please say whether you still need help
Oh, and please get CS to delete the duplicates.
Avatar of RayGun

ASKER

Yes I do. Still getting the same error:
ArticleInterface should be declared abstract; it does not define itemStateChanged(java.awt.event.ItemEvent) in ArticleInterface
 ... and please also state the exact error message you are getting.
ASKER CERTIFIED SOLUTION
Avatar of schybert
schybert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
 RayGun did you try my suggestion?
 ... and please stop hitting refresh all the time... You end up posting more questions. Instead click on the "Reload this question" link on the top-left of the page.
Avatar of RayGun

ASKER

Well you'll have to substitute the capital 'I' to 'i' in itemStateChanged...

Thnx, god damn I need a break. :)
 Hmm I do not see why my *solution* wouldn't satisfy you.
I think that qirionis have already suggested this.
 At least his problem is solved. :-)
Avatar of RayGun

ASKER

I'm sorry girionis, I missed it. You were right all the time. I'll be more allert in the future and be on the lookout for your excellent advise. Thank you.
Please clean up the question mess with CS now RayGun.
Now I feel like a point thief :-( I'll hand the points over to girionis asap :-)
 schybert you don't have to do this, your help was valuable as well :-) It's just nice when people appreciate your help, that's all. It's not matter of points, a simple thank you is enough :-)

  RayGun you're welcome. I am glad we all helped you.
Too late... already posted the question... So go pick those points up... or else... ;-)