i have a jtable calendar program and i want the user to be able to click on the dates and i wrote a mouse listener and added it to the jtable nut its not firing .....what should i do my deadline is tomorrow....
stultuske 1,116 Posting Maven Featured Poster
without seeing any code, or any error message/stacktrace, bit hard for us to tell. If your deadline is tomorrow, well ... remember this next time: trying to get it done last minute usually blows up in your face.
Most likely, there's something wrong or missing in your code, but we can only speculate about that.
hermela_1 0 Newbie Poster
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package calendarprogram1;
/**
*
* @author shady
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//import static notifyme.CalendarProgram.frmMain;
public class CalendarProgram1 extends JFrame{
static JLabel lblMonth, lblYear;
static JButton btnPrev, btnNext;
static JTable tblCalendar;
static JComboBox cmbYear;
static JFrame frmMain;
static Container pane;
static DefaultTableModel mtblCalendar; //Table model
static JScrollPane stblCalendar; //The scrollpane
static JPanel pnlCalendar;
static int realYear, realMonth, realDay, currentYear, currentMonth;
public static void main (String args[]){
//Look and feel
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch (ClassNotFoundException e) {}
catch (InstantiationException e) {}
catch (IllegalAccessException e) {}
catch (UnsupportedLookAndFeelException e) {}
//Prepare frame
frmMain = new JFrame ("NOTAM"); //Create frame
frmMain.setSize(330, 375); //Set size to 400x400 pixels
pane = frmMain.getContentPane(); //Get content pane
pane.setLayout(null); //Apply null layout
frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked
// pane.setSize(1300, 1200);
//frmMain.setSize(1300, 1200);
//Create controls
lblMonth = new JLabel ("January");
lblYear = new JLabel ("Change year:");
cmbYear = new JComboBox();
btnPrev = new JButton ("<<");
btnNext = new JButton (">>");
mtblCalendar = new DefaultTableModel(){@Override
public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};
tblCalendar = new JTable(mtblCalendar);
stblCalendar = new JScrollPane(tblCalendar);
//stblCalendar.setSize(1300, 1200);
pnlCalendar = new JPanel(null);
tblCalendar.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//tblCalendar.setPreferredSize(new Dimension(1300,1200));
// frmMain.getContentPane().add(new JScrollPane(tblCalendar));
//Set border
pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
//pnlCalendar.setSize(1300,1200);
//Register action listeners
btnPrev.addActionListener(new CalendarProgram1.btnPrev_Action());
btnNext.addActionListener(new CalendarProgram1.btnNext_Action());
cmbYear.addActionListener(new CalendarProgram1.cmbYear_Action());
HandlerClass Handler = new HandlerClass();
tblCalendar.addMouseListener(Handler);
//Add controls to pane
pane.add(pnlCalendar);
pnlCalendar.add(lblMonth);
pnlCalendar.add(lblYear);
pnlCalendar.add(cmbYear);
pnlCalendar.add(btnPrev);
pnlCalendar.add(btnNext);
pnlCalendar.add(stblCalendar);
//Set bounds
pnlCalendar.setBounds(0, 0, 1320, 1335);
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 100, 25);
lblYear.setBounds(10, 305, 80, 20);
cmbYear.setBounds(230, 305, 80, 20);
btnPrev.setBounds(10, 25, 50, 25);
btnNext.setBounds(260, 25, 50, 25);
stblCalendar.setBounds(10, 50, 300, 250);
//Make frame visible
frmMain.setResizable(true);
frmMain.setVisible(true);
//frmMain.pack();
// frmMain.setSize(1300,1200);
//Get real month/year
GregorianCalendar cal = new GregorianCalendar(); //Create calendar
realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
realMonth = cal.get(GregorianCalendar.MONTH); //Get month
realYear = cal.get(GregorianCalendar.YEAR); //Get year
currentMonth = realMonth; //Match month and year
currentYear = realYear;
//Add headers
String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
for (int i=0; i<7; i++){
mtblCalendar.addColumn(headers[i]);
}
tblCalendar.getParent().setBackground(tblCalendar.getBackground()); //Set background
//No resize/reorder
tblCalendar.getTableHeader().setResizingAllowed(false);
tblCalendar.getTableHeader().setReorderingAllowed(false);
//Single cell selection
tblCalendar.setColumnSelectionAllowed(true);
tblCalendar.setRowSelectionAllowed(true);
tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//Set row/column count
tblCalendar.setRowHeight(38);
mtblCalendar.setColumnCount(7);
mtblCalendar.setRowCount(6);
//Populate table
for (int i=realYear-100; i<=realYear+100; i++){
cmbYear.addItem(String.valueOf(i));
}
//Refresh calendar
refreshCalendar (realMonth, realYear); //Refresh calendar
}
public static class HandlerClass implements MouseListener{
@Override
public void mouseClicked(MouseEvent event){
tblCalendar.setBackground(Color.BLUE);
}
@Override
public void mousePressed(MouseEvent event){
tblCalendar.setBackground(Color.BLACK);
}
@Override
public void mouseReleased(MouseEvent event){
tblCalendar.setBackground(Color.CYAN);
}
@Override
public void mouseEntered(MouseEvent event){
tblCalendar.setBackground(Color.GREEN);
}
@Override
public void mouseExited(MouseEvent event){
tblCalendar.setBackground(Color.ORANGE);
}
}
public static void refreshCalendar(int month, int year){
//Variables
String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int nod, som; //Number Of Days, Start Of Month
//Allow/disallow buttons
btnPrev.setEnabled(true);
btnNext.setEnabled(true);
if (month == 0 && year <= realYear-10){btnPrev.setEnabled(false);} //Too early
if (month == 11 && year >= realYear+100){btnNext.setEnabled(false);} //Too late
lblMonth.setText(months[month]); //Refresh the month label (at the top)
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 180, 25); //Re-align label with calendar
cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box
//Clear table
for (int i=0; i<6; i++){
for (int j=0; j<7; j++){
mtblCalendar.setValueAt(null, i, j);
}
}
//Get first day of month and number of days
GregorianCalendar cal = new GregorianCalendar(year, month, 1);
nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
som = cal.get(GregorianCalendar.DAY_OF_WEEK);
//Draw calendar
for (int i=1; i<=nod; i++){
int row = new Integer((i+som-2)/7);
int column = (i+som-2)%7;
mtblCalendar.setValueAt(i, row, column);
}
//Apply renderers
tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new CalendarProgram1.tblCalendarRenderer());
}
static class tblCalendarRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent (JTable table, Object value, boolean selected, boolean focused, int row, int column){
super.getTableCellRendererComponent(table, value, selected, focused, row, column);
if (column == 0 || column == 6){ //Week-end
setBackground(new Color(255, 220, 220));
}
else{ //Week
setBackground(new Color(255, 255, 255));
}
if (value != null){
if (Integer.parseInt(value.toString()) == realDay && currentMonth == realMonth && currentYear == realYear){ //Today
setBackground(new Color(220, 220, 255));
}
}
setBorder(null);
setForeground(Color.black);
return this;
}
}
static class btnPrev_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (currentMonth == 0){ //Back one year
currentMonth = 11;
currentYear -= 1;
}
else{ //Back one month
currentMonth -= 1;
}
refreshCalendar(currentMonth, currentYear);
}
}
static class btnNext_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (currentMonth == 11){ //Foward one year
currentMonth = 0;
currentYear += 1;
}
else{ //Foward one month
currentMonth += 1;
}
refreshCalendar(currentMonth, currentYear);
}
}
static class cmbYear_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (cmbYear.getSelectedItem() != null){
String b = cmbYear.getSelectedItem().toString();
currentYear = Integer.parseInt(b);
refreshCalendar(currentMonth, currentYear);
}
}
}
}
hermela_1 0 Newbie Poster
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package calendarprogram1;
/**
*
* @author shady
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//import static notifyme.CalendarProgram.frmMain;
public class CalendarProgram1 extends JFrame{
static JLabel lblMonth, lblYear;
static JButton btnPrev, btnNext;
static JTable tblCalendar;
static JComboBox cmbYear;
static JFrame frmMain;
static Container pane;
static DefaultTableModel mtblCalendar; //Table model
static JScrollPane stblCalendar; //The scrollpane
static JPanel pnlCalendar;
static int realYear, realMonth, realDay, currentYear, currentMonth;
public static void main (String args[]){
//Look and feel
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch (ClassNotFoundException e) {}
catch (InstantiationException e) {}
catch (IllegalAccessException e) {}
catch (UnsupportedLookAndFeelException e) {}
//Prepare frame
frmMain = new JFrame ("NOTAM"); //Create frame
frmMain.setSize(330, 375); //Set size to 400x400 pixels
pane = frmMain.getContentPane(); //Get content pane
pane.setLayout(null); //Apply null layout
frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked
// pane.setSize(1300, 1200);
//frmMain.setSize(1300, 1200);
//Create controls
lblMonth = new JLabel ("January");
lblYear = new JLabel ("Change year:");
cmbYear = new JComboBox();
btnPrev = new JButton ("<<");
btnNext = new JButton (">>");
mtblCalendar = new DefaultTableModel(){@Override
public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};
tblCalendar = new JTable(mtblCalendar);
stblCalendar = new JScrollPane(tblCalendar);
//stblCalendar.setSize(1300, 1200);
pnlCalendar = new JPanel(null);
tblCalendar.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//tblCalendar.setPreferredSize(new Dimension(1300,1200));
// frmMain.getContentPane().add(new JScrollPane(tblCalendar));
//Set border
pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
//pnlCalendar.setSize(1300,1200);
//Register action listeners
btnPrev.addActionListener(new CalendarProgram1.btnPrev_Action());
btnNext.addActionListener(new CalendarProgram1.btnNext_Action());
cmbYear.addActionListener(new CalendarProgram1.cmbYear_Action());
HandlerClass Handler = new HandlerClass();
tblCalendar.addMouseListener(Handler);
//Add controls to pane
pane.add(pnlCalendar);
pnlCalendar.add(lblMonth);
pnlCalendar.add(lblYear);
pnlCalendar.add(cmbYear);
pnlCalendar.add(btnPrev);
pnlCalendar.add(btnNext);
pnlCalendar.add(stblCalendar);
//Set bounds
pnlCalendar.setBounds(0, 0, 1320, 1335);
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 100, 25);
lblYear.setBounds(10, 305, 80, 20);
cmbYear.setBounds(230, 305, 80, 20);
btnPrev.setBounds(10, 25, 50, 25);
btnNext.setBounds(260, 25, 50, 25);
stblCalendar.setBounds(10, 50, 300, 250);
//Make frame visible
frmMain.setResizable(true);
frmMain.setVisible(true);
//frmMain.pack();
// frmMain.setSize(1300,1200);
//Get real month/year
GregorianCalendar cal = new GregorianCalendar(); //Create calendar
realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
realMonth = cal.get(GregorianCalendar.MONTH); //Get month
realYear = cal.get(GregorianCalendar.YEAR); //Get year
currentMonth = realMonth; //Match month and year
currentYear = realYear;
//Add headers
String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
for (int i=0; i<7; i++){
mtblCalendar.addColumn(headers[i]);
}
tblCalendar.getParent().setBackground(tblCalendar.getBackground()); //Set background
//No resize/reorder
tblCalendar.getTableHeader().setResizingAllowed(false);
tblCalendar.getTableHeader().setReorderingAllowed(false);
//Single cell selection
tblCalendar.setColumnSelectionAllowed(true);
tblCalendar.setRowSelectionAllowed(true);
tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//Set row/column count
tblCalendar.setRowHeight(38);
mtblCalendar.setColumnCount(7);
mtblCalendar.setRowCount(6);
//Populate table
for (int i=realYear-100; i<=realYear+100; i++){
cmbYear.addItem(String.valueOf(i));
}
//Refresh calendar
refreshCalendar (realMonth, realYear); //Refresh calendar
}
public static class HandlerClass implements MouseListener{
@Override
public void mouseClicked(MouseEvent event){
tblCalendar.setBackground(Color.BLUE);
}
@Override
public void mousePressed(MouseEvent event){
tblCalendar.setBackground(Color.BLACK);
}
@Override
public void mouseReleased(MouseEvent event){
tblCalendar.setBackground(Color.CYAN);
}
@Override
public void mouseEntered(MouseEvent event){
tblCalendar.setBackground(Color.GREEN);
}
@Override
public void mouseExited(MouseEvent event){
tblCalendar.setBackground(Color.ORANGE);
}
}
public static void refreshCalendar(int month, int year){
//Variables
String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int nod, som; //Number Of Days, Start Of Month
//Allow/disallow buttons
btnPrev.setEnabled(true);
btnNext.setEnabled(true);
if (month == 0 && year <= realYear-10){btnPrev.setEnabled(false);} //Too early
if (month == 11 && year >= realYear+100){btnNext.setEnabled(false);} //Too late
lblMonth.setText(months[month]); //Refresh the month label (at the top)
lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 25, 180, 25); //Re-align label with calendar
cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box
//Clear table
for (int i=0; i<6; i++){
for (int j=0; j<7; j++){
mtblCalendar.setValueAt(null, i, j);
}
}
//Get first day of month and number of days
GregorianCalendar cal = new GregorianCalendar(year, month, 1);
nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
som = cal.get(GregorianCalendar.DAY_OF_WEEK);
//Draw calendar
for (int i=1; i<=nod; i++){
int row = new Integer((i+som-2)/7);
int column = (i+som-2)%7;
mtblCalendar.setValueAt(i, row, column);
}
//Apply renderers
tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new CalendarProgram1.tblCalendarRenderer());
}
static class tblCalendarRenderer extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent (JTable table, Object value, boolean selected, boolean focused, int row, int column){
super.getTableCellRendererComponent(table, value, selected, focused, row, column);
if (column == 0 || column == 6){ //Week-end
setBackground(new Color(255, 220, 220));
}
else{ //Week
setBackground(new Color(255, 255, 255));
}
if (value != null){
if (Integer.parseInt(value.toString()) == realDay && currentMonth == realMonth && currentYear == realYear){ //Today
setBackground(new Color(220, 220, 255));
}
}
setBorder(null);
setForeground(Color.black);
return this;
}
}
static class btnPrev_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (currentMonth == 0){ //Back one year
currentMonth = 11;
currentYear -= 1;
}
else{ //Back one month
currentMonth -= 1;
}
refreshCalendar(currentMonth, currentYear);
}
}
static class btnNext_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (currentMonth == 11){ //Foward one year
currentMonth = 0;
currentYear += 1;
}
else{ //Foward one month
currentMonth += 1;
}
refreshCalendar(currentMonth, currentYear);
}
}
static class cmbYear_Action implements ActionListener{
public void actionPerformed (ActionEvent e){
if (cmbYear.getSelectedItem() != null){
String b = cmbYear.getSelectedItem().toString();
currentYear = Integer.parseInt(b);
refreshCalendar(currentMonth, currentYear);
}
}
}
}
hermela_1 0 Newbie Poster
i wasnt trying to do it last minute...i have been on it for weeks
im just a beginner and research took up my time....and the handler class(mouseevent) works when i apply it to the scroll panel but doesnt work on the jtable
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Your problem description is wrong.
I ran your code with a print statement in the mouseClicked method as it WAS being called. It's the setBackground that's not working - presumably because you have a custom cell renderer that sets the background to fixed values.
ps: I ran this on a Mac and the layout is a mess because you have used a null layout manager and chosen pixel sizes that are (presumably) OK on your machine, but absolutely not portable. That's why we have layout managers.
hermela_1 0 Newbie Poster
hey you are right the problem was with the setbackground function....
i have this other class(gui) that takes in the appointment details from the user and i added it to the mouse clicked method and it works...here is the code
hermela_1 0 Newbie Poster
public void mouseClicked(MouseEvent event){
// tblCalendar.setBackground(Color.BLUE);
InputWindow inp = null;
try {
inp = new InputWindow();
} catch (ParseException ex) {
Logger.getLogger(CalendarProgram.class.getName()).log(Level.SEVERE, null, ex);
}
inp.setVisible(true);
}
hermela_1 0 Newbie Poster
one more thing...after a cell is clicked on i want it to change colors...any ideas????
hermela_1 0 Newbie Poster
thanks for all the help james and stultuske...i have one last question and i wont bother u no more.....so how can should i display the appointment details the user puts in???? here is the code for the input window...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package notifyme;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import java.text.ParseException;
import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
;/**
*
* @author hermela
*/
public class InputWindow extends JFrame {
static Container pane;
private JLabel EQUIPMENT;
private JLabel Location;
private JLabel DATE;
private JLabel TIME,TYPE,space,space1;
private JButton enter;
private JComboBox location1, equipment1,type1;
private Hashtable<Object, Object> subItems = new Hashtable<Object, Object>();
private JTextField time;
private JSpinner jSpinner1;
//private java.text.SimpleDateFormat tf;
DateComboBox dcb = new DateComboBox();
private static String[] Lnames = {"SelectOne","Addis Ababa", "Dire Dawa", "Mekelle", "Arbaminch", "Gode", "Gore", "Gawassa"};
private static String[] Elist = {
"SelectOne","COMMUNICATION","NAVIGATION","SURVEILLANCE"};
private static String[] Clist = {
"SelectCommEqui","VHF121.9","VHF118.1","125.1","125.2","VSAT"};
private static String[] Nlist = {
"SelectNavEqui","VOR","DME","ILS","DVOR","GP","AB Beacon","BL Beacon"};
private static String[] Slist = {
"SelectSurveillanceEqui","PSR","SSR","ADS-B",};
public InputWindow() throws ParseException{
super("Notification Input Window");
setLayout(new FlowLayout());
final Container pane = getContentPane();
pane.setLayout(new GridLayout(8,8));
EQUIPMENT = new JLabel("EQUIPMENT");
TYPE =new JLabel("TYPE");
equipment1= new JComboBox(Elist);
SelectType st = new SelectType();
equipment1.addActionListener(st);
//equipment1.addItemListener(this);
type1 = new JComboBox();
//type.addItemListener(this);
String[] subItems1 = {
"SelectCommEqui","VHF121.9","VHF118.1","125.1","125.2","VSAT"};
subItems.put(Elist[1], subItems1);
String[] subItems2 = {
"SelectNavEqui","VOR","DME","ILS","DVOR","GP","AB Beacon","BL Beacon"};
subItems.put(Elist[2], subItems2);
String[] subItems3 = {
"SelectSurveillanceEqui","PSR","SSR","ADS-B",};
subItems.put(Elist[3], subItems3);
// mainComboBox.setSelectedIndex(1);
Location = new JLabel("LOCATION");
location1 = new JComboBox(Lnames);
DATE = new JLabel("DATE");
TIME = new JLabel("TIME");
time = new JTextField();
Date date = new Date();
SpinnerDateModel sm =
new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
jSpinner1 = new javax.swing.JSpinner(sm);
JSpinner.DateEditor de = new JSpinner.DateEditor(jSpinner1, "HH:mm:ss");
jSpinner1.setEditor(de);
clickEnter enter1= new clickEnter();
enter.addActionListener(enter1);
space = new JLabel();
space1 = new JLabel();
enter = new JButton("ENTER");
pane.add(EQUIPMENT);
pane.add(equipment1);
pane.add(TYPE);
pane.add(type1);
pane.add(Location);
pane.add(location1);
pane.add(DATE);
pane.add(dcb);
pane.add(TIME);
pane.add(jSpinner1);
//pane.add(time);
pane.add(space);
pane.add(space1);
pane.add(enter);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1300,1200);
setVisible(true);
}
class SelectType implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String item = (String) equipment1.getSelectedItem();
Object o = subItems.get(item);
if (o == null) {
type1.setModel(new DefaultComboBoxModel());
} else {
type1.setModel(new DefaultComboBoxModel((String[]) o));
}
}
}
class clickEnter implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
;
}
}
}
hermela_1 0 Newbie Poster
i want to make the enter button save all the details in an array or smthng for later display...when a user clicks on a date for the second time i want them to be able to view what they put in...help!!!!!!!!!!! lot to do no knowledge on hw to do it :(
stultuske 1,116 Posting Maven Featured Poster
I wouldn't start with the enter key yet, first start with buttons, and the listeners you have so far.
Have the information you enter stored (in the application in memory, and on closing the application, on your hard drive in an xml file (for example)).
That way, once you choose the same date a second time, you just have to load the previously entered information.
hermela_1 0 Newbie Poster
okay so i need to create a database and what ever the user enters must go there???? but i dont know how to handle xml in java...send me open source library links pls
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
The easiest route into/out of XML is the XMLEncode / XMLDecode classes that are part of the standard Java API. See https://docs.oracle.com/javase/8/docs/api/java/beans/XMLEncoder.html
hermela_1 0 Newbie Poster
i wrote this for the enter button but its still not working....it made my program even worse...now when i click on the dates it puts out error instead of opening the input window...huhhhh pls help
class clickEnter implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
try {
BufferedWriter out = new BufferedWriter(new BufferedWriter(new FileWriter("dateLogs.txt", true)));
String equ= (String)equipment1.getSelectedItem();
String loc= (String)location1.getSelectedItem();
String typ= (String)type1.getSelectedItem();
out.write(equ);
out.newLine();
out.write(loc);
out.newLine();
out.write(typ);
out.newLine();
JOptionPane.showMessageDialog(pane, out);
out.close();
} catch (IOException | HeadlessException event) {
Logger.getLogger(InputWindow.class.getName()).log(Level.SEVERE, null, event);
}
}
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
What exactly is the error message?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.