• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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.


0
RayGun
Asked:
RayGun
  • 8
  • 4
  • 3
  • +4
1 Solution
 
girionisCommented:
>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;
0
 
Venci75Commented:
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();
0
 
membershCommented:
You had implemented the method but missed out 'd' in itemStateChanged(ItemEvent e).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

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

0
 
umangjoshiCommented:
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


0
 
RayGunAuthor Commented:
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.
0
 
CEHJCommented:
Please say whether you still need help
0
 
CEHJCommented:
Oh, and please get CS to delete the duplicates.
0
 
RayGunAuthor Commented:
Yes I do. Still getting the same error:
ArticleInterface should be declared abstract; it does not define itemStateChanged(java.awt.event.ItemEvent) in ArticleInterface
0
 
girionisCommented:
 ... and please also state the exact error message you are getting.
0
 
schybertCommented:
Well you'll have to substitute the capital 'I' to 'i' in itemStateChanged...
0
 
girionisCommented:
 RayGun did you try my suggestion?
0
 
girionisCommented:
 ... 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.
0
 
RayGunAuthor Commented:
Well you'll have to substitute the capital 'I' to 'i' in itemStateChanged...

Thnx, god damn I need a break. :)
0
 
girionisCommented:
 Hmm I do not see why my *solution* wouldn't satisfy you.
0
 
Venci75Commented:
I think that qirionis have already suggested this.
0
 
girionisCommented:
 At least his problem is solved. :-)
0
 
RayGunAuthor Commented:
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.
0
 
CEHJCommented:
Please clean up the question mess with CS now RayGun.
0
 
schybertCommented:
Now I feel like a point thief :-( I'll hand the points over to girionis asap :-)
0
 
girionisCommented:
 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.
0
 
schybertCommented:
Too late... already posted the question... So go pick those points up... or else... ;-)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 8
  • 4
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now