GUI question on drawing x & y axis

hey, im in the process of creating a gui that prints and sorts the bar graph according to the sorting method the user chooses through a menu. i havent came across any problems on getting the data and sorting it until it came to drawing out the bar graph. question is ive looked every where even my labs and lecture notes on how to draw GUI's but none mentioned how to draw and label the x and y axis.
my y axis is the price which is 0-100 any suggestions on how i can draw out the y axis and have it increment with either $5 or $10 up till 100. and is it possible to put a letter on top of the bar graph that it belongs to?
such as bar graph #1 can be labeled as A, which is placed on top of it because my x axis will not be given values. so bar graph#1 will be A ,with a price of $7
any suggestions on how i can get started on drawing my graph or sites that i can learn from?

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.text.NumberFormat;
import javax.swing.*;
public class GraphTest
    public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new GraphPanel());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
class GraphPanel extends JPanel
    final int PAD;
    Font font;
    NumberFormat nf;
    public GraphPanel()
        PAD = 38;
        font = new Font("lucida bright regular", Font.PLAIN, 14);
        nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        nf.setMinimumFractionDigits(2);
        setBackground(Color.white);
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setFont(font);
        FontRenderContext frc = g2.getFontRenderContext();
        int w = getWidth();
        int h = getHeight();
        double yInc = (h - 2*PAD)/10.0;
        // ordinate
        g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
        // tick marks
        double x = PAD, y = h - PAD - yInc;
        for(int j = 0; j < 10; j++)
            g2.draw(new Line2D.Double(x - 2, y, x, y));
            y -= yInc;
        // labels
        y = h - PAD;
        float width, height, sx, sy;
        for(int j = 0; j <= 10; j++)
            String s = "$" + j;
            width = (float)font.getStringBounds(s, frc).getWidth();
            LineMetrics lm = font.getLineMetrics(s, frc);
            height = lm.getAscent() - lm.getDescent();
            sx = (float)(x - 4 - width);
            sy = (float)(y + height/2);
            g2.drawString(s, sx, sy);
            y -= yInc;
        // abcissa
        g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
        // show value = 7
        double x1, x2, xInc = 40;
        double value = 7.00;
        String s = "$" + nf.format(value);
        width = (float)font.getStringBounds(s, frc).getWidth();
        LineMetrics lm = font.getLineMetrics(s, frc);
        height = lm.getAscent() - lm.getDescent();
        x1 = PAD + 3 * xInc;
        x2 = x1 + xInc;
        y = (h - PAD) - (value) * (h - 2*PAD)/10.0;
        g2.draw(new Line2D.Double(x1, y, x1, h - PAD));
        g2.draw(new Line2D.Double(x1, y, x2, y));
        g2.draw(new Line2D.Double(x2, y, x2, h - PAD));
        // label bar top
        sx = (float)(x2 - (xInc + width)/2);
        sy = (float)(y - 2);
        g2.drawString(s, sx, sy);
}

Similar Messages

  • Reversi GUI question, A LOT of code in here!

    okay, so I've been working on his code for a long time. A REAL long time, working on it bit by bit, and all I got left is the Reversi's GUI. Basically I want to use the Jbutton and have x represent black and o represent white. I'm getting stuck on how to go about it. Any ideas?
    Here's alllll the code.
    package com.Ozo.games.reversi;
    * This utility class provides a number of static constants and
    * methods that provide abstractions for player colors and moves.
    * Colors and moves could be implemented as objects of separate
    * classes, but instead we represent them as integers and provide
    * the abstraction via these operations.
    public class Reversi {
         public static final int Black = 1;
         public static final int White = 2;
         public static final int Empty = 0;
          * Gives the color of a player's opponent.
          * @param color of this player.
          * @return color of the opponent.
         public static int playerOpposite(int color) {
              if (color == Black) return White;
              if (color == White) return Black;
              throw new Error("Player must be Black or White");
          * Compare two scores and determine whether the first is better than the second.
          * Better for black means more positive.  Better for white means more negative.
          * @param colorAsking
          * @param score1
          * @param score2
          * @return whether score1 is better than score2, as far as colorAsking is concerned.
         public static boolean isBetterScore(int colorAsking, int score1, int score2) {
              if (colorAsking == Black) return score1 > score2;
              if (colorAsking == White) return score1 < score2;
              throw new Error("Player must be Black or White");
          * Encode a move from this position as an integer.
          * A "pass" move is recorded as (-1,-1).
          * @param pos the board this move is for.
          * @param row the row at which the piece is placed.
          * @param col the column at which the piece is placed.
          * @return encoded move.
         public static int newMove(ReversiPosition pos, int row, int col) {
              return row * pos.ncols() + col;
          * A "pass" move.  I.e. no piece is placed.
         public static int newMovePass(ReversiPosition pos) {
              return newMove(pos, -1, -1);
          * Find the row of an encoded move.
          * @param pos the board this move is for.
          * @param move
          * @return the row.
         public static int moveRow(ReversiPosition pos, int move) {
              return move / pos.ncols();
          * Find the column of an encoded move.
          * @param pos the board this move is for.
          * @param move
          * @return the column.
         public static int moveCol(ReversiPosition pos, int move) {
              return move % pos.ncols();
    package com.Ozo.games.reversi;
    * Top-level driver for a Reversi game.
    public class ReversiGame {
         private ReversiPosition   _pos;
         private int               _toMoveColor;
         private ReversiTextIO     _userInterface;
         public ReversiGame(int nrows, int ncols) {
              _pos           = new ReversiPosition(nrows, ncols);
              _toMoveColor   = Reversi.Black;
              _userInterface = null;
              ReversiRules.setStartingPosition(_pos);
         public void setUserInterface(ReversiTextIO ui) {
              _userInterface = ui;
         public ReversiPosition currentPosition() { return _pos; }
         public int             toMoveColor()     { return _toMoveColor; }
         public void getHumanMoveAndApplyIt() {
              if (ReversiRules.countLegalMoves(_pos, _toMoveColor) != 0) {
                   int move = _userInterface.getMove(_pos, _toMoveColor);
                   _pos.applyMove(move, _toMoveColor);
              else
                   _userInterface.message("You have no move.  I get another turn.");
              _toMoveColor = Reversi.playerOpposite(_toMoveColor);
         public void getComputerMoveAndApplyIt() {
              if (ReversiRules.countLegalMoves(_pos, _toMoveColor) != 0) {
                   int move = ReversiStrategy.findBestMove(_pos, _toMoveColor);
                   _pos.applyMove(move, _toMoveColor);
              else
                   _userInterface.message("I have no move.  You get another turn.");
              _toMoveColor = Reversi.playerOpposite(_toMoveColor);
         public void play() {
              _userInterface.output(_pos);
              for (;;) {
                   if (ReversiRules.isGameOver(_pos, _toMoveColor)) { gameOverMessage(); break; }
                   getHumanMoveAndApplyIt();
                   _userInterface.output(_pos);
                   if (ReversiRules.isGameOver(_pos, _toMoveColor)) { gameOverMessage(); break; }
                   getComputerMoveAndApplyIt();
                   _userInterface.output(_pos);
         public void gameOverMessage() {
              _userInterface.message("Game over...");
              int winner = ReversiRules.winningColor(_pos, _toMoveColor);
              if      (winner == Reversi.Black) _userInterface.message("Black wins.");
              else if (winner == Reversi.White) _userInterface.message("White wins.");
              else    _userInterface.message("Draw.");
    package com.Ozo.games.reversi;
    * The main class to start a Reversi game as an application.
    public class ReversiMain {
         public static void main(String[] args) {
              ReversiGame   game = new ReversiGame(8, 8);
              ReversiTextIO tui  = new ReversiTextIO(System.in, System.out);
              game.setUserInterface(tui);
              game.play();
    }

    package com.Ozo.games.reversi;
    * This class provides all of the intelligence for a program to play Reversi.
    * It contains all the knowledge of play strategy.  (The knowledge of the rules
    * is maintained by the ReversiRules class.)
    * The principal method is findBestMove, which does an exhaustive search a number
    * of plys deep, and then applies a hueristic position evaluation function.
    public class ReversiStrategy {
         private static int PlysToTry = 6;
          * Find the best move for the player of the given color.
          * If there is no move, then return "pass".
          * @param pos the position to be evaluated.
          * @param toMoveColor the color of player to move.
          * @param plysRemaining the depth to examine (must be >= 1).
          * @return the best move within the default horizon.
         public static int findBestMove(ReversiPosition pos, int toMoveColor) {
              return findBestMove(pos, toMoveColor, PlysToTry).move;
          * This class is used to return a pair of values:  the best move and the score it achieves
          * after the number of plys remaining are played.
         public static class BestMove {
              public int move;
              public int score;
              public BestMove(int m, int s) { move = m; score = s; }
          * Find the best move for the player of the given color within
          * the given number of plys.
          * @param pos the position to be evaluated.
          * @param toMoveColor the color of player to move.
          * @param plysRemaining the depth to examine (must be >= 1).
          * @return a BestMove object returning the best move found and the score it achieves.
         public static BestMove findBestMove(ReversiPosition pos, int toMoveColor, int plysRemaining) {
              if (plysRemaining < 1) throw new Error("findBestMove needs plysRemaining >= 1");
              // Generate the legal moves.  If there are none, then pass.
              int opponentColor = Reversi.playerOpposite(toMoveColor);
              int[] moves = ReversiRules.generateMoves(pos, toMoveColor);
              if (moves.length == 0) {
                   if (plysRemaining == 1)
                        return new BestMove(Reversi.newMovePass(pos), summaryScore(pos));
                   else
                        return findBestMove(pos, opponentColor, plysRemaining-1);
              // Try all the moves.  Re-use one position object to make the move.
              ReversiPosition afterMove = pos.copy();
              // Start with a hypothetical worst scenario and then look for what's better.
              afterMove.fill(opponentColor);
              int bestScore = 2*summaryScore(afterMove);  // Worse that the worst possible real score.
              int bestIndex = -1;
              for (int i = 0; i < moves.length; i++) {
                   pos.copyInto(afterMove);      // Re-use the position object.
                   afterMove.applyMove(moves, toMoveColor);
                   int thisScore = (plysRemaining == 1) ?
                        summaryScore(afterMove) :
                        findBestMove(afterMove, opponentColor, plysRemaining - 1).score;
                   if (Reversi.isBetterScore(toMoveColor, thisScore, bestScore)) {
                        bestScore = thisScore;
                        bestIndex = i;
              if (bestIndex == -1) System.out.println("Number of moves " + moves.length + " plys " + plysRemaining);
              return new BestMove(moves[bestIndex], bestScore);
         * Examine contents of square and return 1 for Black, -1 for White, 0 for Empty.
         * Useful in computing scores.
         * @param r row number.
         * @param c column number.
         * @return +1/-1/0
         private static int squareVal(ReversiPosition pos, int r, int c) {
              if (pos.getSquare(r, c) == Reversi.White) return -1;
              if (pos.getSquare(r, c) == Reversi.Black) return +1;
              return 0;
         * Count the number of black squares minus the number of white squares.
         * @return difference in number of black and white squares.
         public static int squareScore(ReversiPosition pos) {
              int nBminusW = 0;
              for (int r = 0; r < pos.nrows(); r++)
                   for (int c = 0; c < pos.ncols(); c++)
                        nBminusW += squareVal(pos, r, c);
              return nBminusW;
         * Count the number of black edge squares minus the number of white ones.
         * @return difference in number of black and white squares.
         public static int edgeScore(ReversiPosition pos) {
              int nBminusW = 0;
              // East and west edges.
              for (int r = 1; r < pos.nrows()-1; r++)
                   nBminusW += squareVal(pos, r, 0) + squareVal(pos, r, pos.ncols()-1);
              // North and south edges.
              for (int c = 1; c < pos.ncols()-1; c++)
                   nBminusW += squareVal(pos, 0, c) + squareVal(pos, pos.nrows()-1, c);
              return nBminusW;
         * Count the number of black corner squares minus the number of white ones.
         * @return difference in number of black and white squares.
         public static int cornerScore(ReversiPosition pos) {
              int rlast = pos.nrows()-1, clast = pos.ncols()-1;
              return squareVal(pos, 0, 0) + squareVal(pos, 0, clast) +
              squareVal(pos, rlast, 0) + squareVal(pos, rlast, clast);
         * Compute a heuristic score for a given position. The more positive,
         * the better for Black. Controlling corners is weighted most heavily,
         * folowed by sides, then regular squares. In principle a different weight
         * function should be used at the end of the game, since then it is really
         * the total number of squares that counts.
         * @param pos the position to be assessed.
         * @return the numerical score, with positive being good for Black, negative good for White.
         public static int summaryScore(ReversiPosition pos) {
                   return squareScore(pos) + 8*edgeScore(pos) + 20*cornerScore(pos);
    }Edited by: Oozaro on Nov 19, 2009 12:41 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • A GUI Question

    How do I put in a button for each day of the calender (done in this code):
    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);
    I want a screen that I have coded to  pop-up which has tasks for the day. This is the Window I want for to pop-up when I click the button:
    package Calender;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MainWindow extends JFrame
         JMenuBar menubar;
         JMenu m1, m2, m3, m4;
         JMenuItem add1, remove, display, about;
         public MainWindow()
              setLayout(new FlowLayout());
              menubar = new JMenuBar();
              add(menubar);
              m1 = new JMenu("Add a task..");
              m2 = new JMenu("Remove a task..");
              m3 = new JMenu("Display tasks..");
              m4 = new JMenu("About..");
              menubar.add(m1);
              menubar.add(m2);
              menubar.add(m3);
              menubar.add(m4);
              add1 = new JMenuItem("add");
              m1.add(add1);
              remove = new JMenuItem("remove");
              m2.add(remove);
              display = new JMenuItem("display");
              m3.add(display);
              about = new JMenuItem("about");
              m4.add(about);
              setJMenuBar(menubar);
              EventA e = new EventA();
              add1.addActionListener(e);
              EventRem i = new EventRem();
              remove.addActionListener(i);
              EventDis a = new EventDis();
              display.addActionListener(a);
              EventAb b = new EventAb();
              about.addActionListener(b);
         public class EventA implements ActionListener
              public void actionPerformed(ActionEvent e)
                   AddWindow gui = new AddWindow(MainWindow.this);
                   gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                   gui.setSize(500,100);
                   gui.setLocation(300,300);
                   gui.setTitle("Add a task...");
                   gui.setVisible(true);
         public class EventAb implements ActionListener
              public void actionPerformed(ActionEvent e)
                   AboutWindow gui = new AboutWindow(MainWindow.this);
                   gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                   gui.setSize(500,100);
                   gui.setLocation(300,300);
                   gui.setTitle("About..");
                   gui.setVisible(true);
         public class EventRem implements ActionListener
              public void actionPerformed(ActionEvent e)
                   RemoveWindow gui = new RemoveWindow(MainWindow.this);
                   gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                   gui.setSize(500,100);
                   gui.setLocation(300,300);
                   gui.setTitle("Remove a task...");
                   gui.setVisible(true);
         public class EventDis implements ActionListener
              public void actionPerformed(ActionEvent e)
                   DisplayWindow gui = new DisplayWindow(MainWindow.this);
                   gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                   gui.setSize(500,100);
                   gui.setLocation(300,300);
                   gui.setTitle("Display tasks...");
                   gui.setVisible(true);
         public static void main(String[] args)
              MainWindow gui = new MainWindow();
              gui.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
              gui.setSize(500, 100);
              gui.setVisible(true);
              gui.setTitle("Main Window");
    Here is my entire calendar class:
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Calendar
         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 scroll plane
         static JPanel pnlCalendar;
         static int realYear, realMonth, realDay, currentYear, currentMonth;
         * Changes days, months, years, etc
         public static void refreshCalendar(int month, int year)
              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-1){btnPrev.setEnabled(false);} //Too early
              if (month == 11 && year >= realYear+5){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
              //ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
              //Clears 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);
              tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new 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 GoBackAction 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 GoNextAction 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 cmbYearAction implements ActionListener
              public void actionPerformed (ActionEvent e)
                   if (cmbYear.getSelectedItem() != null)
                        String b = cmbYear.getSelectedItem().toString();
                        currentYear = Integer.parseInt(b);
                        refreshCalendar(currentMonth, currentYear);
         public static void main (String args[])
              try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
              catch (ClassNotFoundException e) {}
              catch (InstantiationException e) {}
              catch (IllegalAccessException e) {}
              catch (UnsupportedLookAndFeelException e) {}
              //makes the frame for the console
              frmMain = new JFrame ("APCS Calender"); //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
              //Creates the controls for the screan
              lblMonth = new JLabel ("January");
              lblYear = new JLabel ("Change year:");
              cmbYear = new JComboBox();
              btnPrev = new JButton ("<<");
              btnNext = new JButton (">>");
              mtblCalendar = new DefaultTableModel(){public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};
              tblCalendar = new JTable(mtblCalendar);
              stblCalendar = new JScrollPane(tblCalendar);
              pnlCalendar = new JPanel(null);
              //Sets the border for the screen
              pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
              btnPrev.addActionListener(new GoBackAction());
              btnNext.addActionListener(new GoNextAction());
              cmbYear.addActionListener(new cmbYearAction());
              //Add controls to screen
              pane.add(pnlCalendar);
              pnlCalendar.add(lblMonth);
              pnlCalendar.add(lblYear);
              pnlCalendar.add(cmbYear);
              pnlCalendar.add(btnPrev);
              pnlCalendar.add(btnNext);
              pnlCalendar.add(stblCalendar);
              //Set boundaries for day, month, year
              pnlCalendar.setBounds(0, 0, 320, 335);
              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(false);
              frmMain.setVisible(true);
              //Gets the real month, year and day
              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 to screen
              String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
              for (int i=0; i<7; i++){
                   mtblCalendar.addColumn(headers);
              tblCalendar.getParent().setBackground(tblCalendar.getBackground()); //Set background
              //Makes it so that you can't resize or reorder
              tblCalendar.getTableHeader().setResizingAllowed(false);
              tblCalendar.getTableHeader().setReorderingAllowed(false);
              tblCalendar.setColumnSelectionAllowed(true);
              tblCalendar.setRowSelectionAllowed(true);
              tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              //Set row and column count
              tblCalendar.setRowHeight(38);
              mtblCalendar.setColumnCount(7);
              mtblCalendar.setRowCount(6);
              //puts values in the table
              for (int i=realYear-1; i<=realYear+5; i++)
                   cmbYear.addItem(String.valueOf(i));
              //Refresh calendar
              refreshCalendar (realMonth, realYear); //Refresh calendar

    Moderator action: Moved from Java Programming.
    Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.
    Then edit your post and format the code correctly.
    db

  • Question about iDoc- iDoc_xml- soap- axis- ...

    Hi,
    I have to create iDocs, transform these iDocs into xml(iDoc_xml) and send these xmls "soaped" via a https POST to an external webservice (axis 2). The webservice should transform the xml in a xml-format who could be read by an other system. Then the transformed xml will be send to the system. In the other direction I will get state changes from the system, transform this data @ the webservice into an idoc an send this via JCO into the SAP system.
    The first steps are done. I could create an idoc and send it via the Port " soaped to a http destination. But I am not able to read the data within my webservice and the https stuff doesnt work too. Could anybody tell me if there are perhaps Best Practices for this kind of "work". I think my way to send a delivery03 iDoc as an xml to a customer is not the best way. Perhaps its a better idea to send the idOc to the webservice and let the jCo transform this iDoc to XML? Is this generally possible?

    Hi Benjamin,
    In this case
    E1AFKOL is the parent segment.
    E1JSTKL, E1AFABL and E1AFFLL are the child for E1AFKOL.
    The meaning is - for a particular parent segment there can exist 1 - 9999 child segments of E1JSTKL, E1AFABL and E1AFFLL
    This is the parent child relationship
    For the second question
    In the table EDID4
    Let us take this example
    DOCNUM    SEGNUM    SEGNAM    PSGNUM     HLEVEL
    1000            000001       E1AFKOL    000000        01
    1000            000002       E1JSTKL     000001        02
    1000            000003       E1JSTKL     000001        02
    1000            000004       E1JSTKL     000001        02
    1000            000005       E1AFABL     000001        02
    1000            000006       E1AFABL     000001        02
    1000            000007       E1AFABL     000001        02
    1000            000008       E1AFFLL     000001        02
    1000            000009       E1AFVOL     000008        03
    1000            000010       E1AFVOL     000008        03
    1000            000011       E1AFFLL     000001        02
    1000            000012       E1AFVOL     000011        03
    1000            000013       E1AFVOL     000011        03
    1000            000014       E1AFFLL     000001        02
    1000            000015       E1AFVOL     000014        03
    1000            000016       E1AFVOL     000014        03
    Hope this helps.
    Regards
    Arun

  • System.out.println in gui--- question

    Hello People.
    First of all, I'm new to the forums, so if it doesn't belong here, plese tell me where to post questions like this.
    The Problem:
    I have a GUI and another class,which contains the Program.
    Here's the code of my class:
    int Battle(String CharName) {
              System.out.println(CharName + " Is fighting agains a monster");
              while (CharHP > 0 && MonsterHP != 0) {
                   MonsterHP = MonsterHP - CharDmg;
                   System.out.println("The monster has " + MonsterHP + "Hitpoints left ");
                   CharHP = CharHP - MonsterDamage;
                   System.out.println(CharName + " has " + CharHP + " Hitpoints left");
              if (MonsterHP == 0) {
                   System.out.println(CharName + "Has lost the fight!");
                   CharEXP = CharEXP + 20;
                   System.out.println("You have gained " + CharEXP + " Exp");
              if (CharHP == 0) {
                   System.out.println("You have lost the fight!");
              return CharHP;
         }So what would be the code to print all the "System.out.println's" here into the gui test area?

    camickr wrote:
    Check out the [Message Console|http://www.camick.com/java/blog.html?name=message-console].
    Just out of curiosity, how do you come up with ideas for all the awesome stuff on your blog?

  • Administration Port / command line /  console gui question

    In the Admin_ref.pdf doc it says "After enabling the administration port, all Administration Console traffic must connect via the administration port". Does this mean that you can no longer use the web gui console to manage the servers?
    I would like the option to script deployments (deploy ears, stop start servers etc.) via command line to reduce the possibility of user error during routine deployments.
    I do config mgmt. and am not a developer so I may be getting hung up on the language here.
    Thanks,
    gj

    Hi
    For first question the answer is no. With the administration port, you enable the SSL between the admin server and Node manager-managed Servers. You can still use the web console.
    For teh second question, you can use ANT or can use the WLS Scripting ..you can get more details in dev2dev.bea.com
    Jin

  • Repository connection information gui question

    I am going through the "Getting started with oracle data integrator" document (E12641-01). I am at the part where I am supposed to create a work repository(step 5 of page 4-4). Unfortunately, the repostory connection information gui will not allow me to input a name for the work repository in the little text field. The cursor blinks but no text appears when I type. It is as if the text field is locked.
    The following describes my system configuration:
    Microsoft Windows Server 2003 R2 Standard x64 Edition Service Pack 2
    Oracle Data Integrator 11g Standalone Edition Version 11.1.1
    Build ODI_11.1.1.3.0_GENERIC_100623.1635
    Java(TM) Platform 1.6.0_25-ea
    Oracle IDE 11.1.1.3.0
    WebLogic server 10.3
    Oracle Server 11gR1
    I have both JDK 32bit and 64bit packages installed on my 64-bit machine. Apparently, odiclient only works with 32-bit jdk package.

    Question solved:
    http://st-curriculum.oracle.com/obe/fmw/odi/odi_11g/ODImaster_work_repos/ODImaster_work_repos.htm

  • A short GUI question????

    Hi guys...
    I am writing a small program that reads a file in .csv format and creates a html file which is used to display the data contained in the .csv file out in the browser.
    My question is how do you invoke the html file so that you get the html file diplayed in the browser by clicking in the JBotton porvided by the GUI of my program...
    Cheers guys...

    Hi johanup...
    Are you saying that the code shieroi wrote would NOT
    work on Mac, Linux, or Windows ME, 98 or 95. Yes, that's exactly what I said. I'm sorry if I wasn't clear enough. The code works on Windows NT, 2000 and XP by running cmd.exe, the command interpreter on those operating systems. Other OSs don't have that program. (They have similar programs doing similar things, but not with the same name.)
    I checked the BrowserLauncher but I am not sure if it
    is a class contained in the j2sdk 1.4.1.02 I have
    downloaded from the java.sun.com or do you have to
    download it from some site...No, it's not included in Sun's jdk.
    If you have to download it form somewhere can you tell
    me the url...Ehm, that's the URL I gave you.

  • A SAPinst GUI question - can't connect to port 21212

    Hello,
    I'm trying to install a BW 3.0B system 'BSB' using Linux/Oracle on 32-bit Intel hardware.  The Linux is Suse Linux Enterprise Server 9 (SLES9).  The Oracle is 9.2. 
    I was able to see the 1st SAP Installation GUI screen.  The two fields on the screen appeared as follows:
      Installation Host: <i>localhost</i>
      Port: <i>21212</i>
    <u>But when I clicked the 'OK' button, nothing happened.  The screen and the two fields remained the same.</u>  The messages from the UNIX install session, on two attempts using root id, are attached.  There is nothing in the <i>sapinst.log</i> file in the install directory <i>/INSTBW30B/CI</i>.  My Linux Administrator thought  the SAPinst listener is not working.
    The SAPinst I used is version 1.0, from a SAP BW 3.0B Installation CD, published in 2002.
    Please advise.  Thanks.
    Regards,
    Jack Wu
    lsapd002 /home/bsbadm> su -
    Password:
    lsapd002:~ # umask
    0022
    lsapd002:~ # export DISPLAY=10.101.62.19:0.0
    lsapd002:~ # export JAVA_HOME=/INSTBW30B/JAVA/j2sdk1.4.2_09
    lsapd002:~ # export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
    lsapd002:~ # export LD_LIBRARY_PATH=/sapmnt/BSB/exe
    lsapd002:~ # export LD_ASSUME_KERNEL=2.4.1
    lsapd002:~ # export SAPINST_DIR=/INSTBW30B/CI
    lsapd002:~ #
    lsapd002:~ # cd /INSTBW30B/CI
    lsapd002:/INSTBW30B/CI #
    lsapd002:/INSTBW30B/CI # <b>./startinstgui.sh</b>
    Log file: /INSTBW30B/CI/instgui.log
    2005.10.19 08:45:15: JVM version is '1.4.2_09' (1.4)
    2005.10.19 08:45:15: InstGui started.
    Setting javax.swing.plaf.metal.MetalLookAndFeel at com.sap.ins.gui.Main.setPLAF(Main.java:311)
    2005.10.19 08:45:16: SAPinst GUI Version:  2002/03/13   //bc/dev/src/ins/SAPINST/impl/src/gui/src/com/sap/ins/gui
    addXMLListener for sapinstgui at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstlog at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstfile at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstalert at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstguilogon at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    Using In-Q-My XML parser at com.sap.ins.gui.xml.XMLParser.setParser(XMLParser.java:317)
    Connecting to localhost:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)
    Connecting to localhost:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)
    Connecting to localhost:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)
    Connecting to lsapd002:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)
    lsapd002:/INSTBW30B/CI #
    lsapd002:/INSTBW30B/CI # <b>telnet lsapd002 21212</b>
    Trying 10.48.110.58...
    telnet: connect to address 10.48.110.58: Connection refused
    lsapd002:/INSTBW30B/CI #
    lsapd002:/INSTBW30B/CI # <b>./startinstgui.sh -port 21212</b>
    Log file: /INSTBW30B/CI/instgui.log
    2005.10.19 09:41:16: JVM version is '1.4.2_09' (1.4)
    2005.10.19 09:41:16: InstGui started.
    Setting javax.swing.plaf.metal.MetalLookAndFeel at com.sap.ins.gui.Main.setPLAF(Main.java:311)
    2005.10.19 09:41:16: SAPinst GUI Version:  2002/03/13   //bc/dev/src/ins/SAPINST/impl/src/gui/src/com/sap/ins/gui
    addXMLListener for sapinstgui at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstlog at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstfile at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstalert at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    addXMLListener for sapinstguilogon at com.sap.ins.gui.xml.XMLParser.addXMLListener(XMLParser.java:28)
    Using In-Q-My XML parser at com.sap.ins.gui.xml.XMLParser.setParser(XMLParser.java:317)
    Connecting to localhost:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)
    Connecting to localhost:21212 at com.sap.ins.gui.network.Thread.connect(Thread.java:91)
    Not connected. at com.sap.ins.gui.network.Thread.connect(Thread.java:101)

    Hello Daniel,
    Thanks for the quick reply.  The following are the whole story:
    1. When I started, I followed the SAP "<i>BW 3.0B Installation Guide on UNIX/Oracle</i>" and SAP note 580772.  After getting the error message "Floating point exception", I added the missing environment variable <b>LD_ASSUME_KERNEL=2.4.1</b> according SAP note 797084.
    2. Then I tried again:
    lsapd002:/INSTBW30B/CI <b># /sapcd/KERBW30B/SAPINST/UNIX/LINUX_32/INSTALL</b>
    This time I got different error messages:
    ERROR      2005-10-18 10:50:23 [syuxcnodut.cpp:589]
               CSyNodeUtils::isExistingWithType(iastring, bool, ISyNode::eNodeType)
    <u>FSL-02013  Unable to access file /INSTBW30B/CI/keydb.1.xml: Success.</u>
    ERROR      2005-10-18 10:50:24 [iaxxcsihlp.hpp:344]
               main()
    <u>FCO-00034  An error occurred during the installation. Problem: caught an unexpected exception.</u>
    The error message FSL-02013 is confusing.  Was it successful or not?  It appears not.  There is a keydb.xml in the installation directory /INSTBW30B/CI.  But for unknown reason, <b>sapinst</b> couldn't copy it to create keydb.1.xml.  Also, I'm not sure whether FSL-02013 caused FCO-00034, or the two messages are not related?
    3. I looked into the "<i>SAPinst Troubleshooting Guide v 1.20 5/27/2002</i>", found a symptom on p.11, followed the solution part 1:
    lsapd002:/INSTBW30B/CI <b># ./sapinst SAPINST_NO_GUISTART=true</b>
    I got the same error messages as in Step 2.
    4. I tried to fool the installer by doing manually:
    lsapd002:/INSTBW30B/CI <b># cp -p keydb.xml keydb.1.xml</b>
    5. Then tried the installation again
    lsapd002:/INSTBW30B/CI <b># ./sapinst</b>
    I got similar, but not identical error messages
    ERROR      2005-10-18 16:38:18 [syuxcnodut.cpp:589]
               CSyNodeUtils::isExistingWithType(iastring, bool, ISyNode::eNodeType)
    FSL-02013  Unable to access file /INSTBW30B/CI/keydb.<b>2</b>.xml: Success.
    ERROR      2005-10-18 16:38:18 [iaxxcsihlp.hpp:344]
               main()
    FCO-00034  An error occurred during the installation. Problem: caught an unexpected exception.
    <u>Please notice that the FSL-02013 complains about keydb.<b>2</b>.xml this time.</u>
    6. Then I gave up on solution part 1 in the "SAPinst <i>Troubleshooting Guide</i>" and continued with solution part 2, which is to run the shell script <b>startinstgui.sh</b>.  After having difficulty with port 21212, I posted the question in the SDN Forum on 10/19/2005.
    According to your reply, <b>startinstgui.sh</b> is just running the GUI which isn't really the installation.  So I still need to resolve the errors with <b>sapinst</b>, i.e. FSL-02013 and FCO-00034.  Any suggestion?
    Regards,
    Jack Wu

  • Ridiculously dumb question about drawing in JPanel

    Howdy everyone,
    I gotta really stupid question that I cant figure out the answer to. How do I draw an image to a JPanel, when my class inherits from JFrame?
    Thanks,
    Rick

    Ok,
    Problem. The image isnt showing up in the Frame I set up for it. Heres my code. Im trying to get this image to show up in a scollable window. Can anyone tell what the problem with this code is??
    JPanel imgPanel= new JPanel(){
    protected void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawImage(getToolkit().createImage(imstr),imgw,imgh,this);
    imgPanel.setVisible(true);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(new JScrollPane(imgPanel));
    this.setVisible(true);
    Any ideas?
    Thanks
    Rick

  • Some questions on drawing

    hi all, i want to draw out a different shape depending on what key the user pressed, but how do i draw outside of the paint() method? for example, when the user presses 1 on the handphone(emulator), i draw out a rectangle. i tried to check for the key been pressed in paint(), but its like paint() is only been called when the MIDlet starts up, and i can only press a key after everything has been drawn, so nothing gets drawn out.
    public void paint(Graphics g)
    public void drawrect()
    public void drawsquare()
    public void keyPressed(int keyCode)
       //if 1 is pressed..........
       drawrect();
       //if 2 is pressed..........
       drawsquare();
    }

    stupid me i placed the repaint() in the wrong place haha got it working now

  • Labels on GUI question

    Hi, I want to put labels on a GUI that basically continually shows values of various parameters which change regularly. What would be the best way of doing this? I was thinking of just using a thread and putting a loop that continually gets the value of the parameter until the program stops, but how do you actually change what is printed on the label?
    Thanks!

    Hmmm... setText is one thing, but what's this about spinning off a thread to poll parameter values?
    If you want to decouple the code that changes the parameter values from the code
    that notices those values have changed and reacts by changing label text, then
    Grasshopper, I think you should be aware of the Observer Pattern:
    http://sern.ucalgary.ca/courses/SENG/609.04/W98/lamsh/observerLib.html
    http://www.wohnklo.de/patterns/observer.html
    http://c2.com/cgi/wiki?ObserverPattern
    http://www.javaworld.com/javaworld/javaqa/2001-05/04-qa-0525-observer.html
    http://www.research.ibm.com/designpatterns/example.htm

  • Very Basic GUI Question

    Can anyone tell me why this GUI won't display at all? Thanks
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;  //For colors
    import java.awt.event.*;
    public class Baseball extends JFrame {
    public Baseball(){
        setTitle("Baseball!");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
       getContentPane().add(panel,BorderLayout.CENTER);
       panel.setBackground(Color.BLUE);
        setSize(400, 400);
        pack();
        setVisible(true);
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
           java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Baseball();
    }I have no idea what this means: java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() Edited by: Champachikla on Feb 7, 2010 2:01 AM

    Dan_Koldyr wrote:
    1. avoid pack();/setVisible(true); directly in frame constructor But do not neglect to call pack() at some stage before setVisible(true).
    2. invokeLater in main method makes no sense.It does in rare circumstances. (E.G. one visible app. calling the main of another app.)
    So i would suggest modify your code like following
    public Baseball(){
    setSize(400, 400);
    No. The previous poster got it right when talking about setting the preferred size. After pack(), your GUI will be shrunk as well.

  • Netbeans 5.0 GUI question

    Hey guys!
    im a newbie JSF coder and well im in my work term and one of my projects is to develop a Web application(using JSF) to replicate a VB program that my company has but on the web.
    Im on teh front-end stage of the project and reading a JSF(core) book and well they mention a GUI Builder. Im using NetBeans IDE 5.0....is there something within this IDE that i can design a front-end as i would using Visual Basic? Tad annoying if there isn't and it'll take me quite a long itme to actually code something up without a graphical tool :(
    Cheers and many thanks,
    Dan

    Do you get this error when selecting "run" from within NetBeans?
    When I create a project using Netbeans 5.0 beta using the form designer NetBeans automatically adds swing-layout-0.7.jar to the list of libraries in the libraries node in the project window. I didn't do anything fancy.
    Do you get this error if you create another project?
    it works fine for me.

  • JPanel GUI question

    I am writing a program that updates a Jpanel on the gui when a button is clicked ( GUI or editGUI).
    The program currently loadsup to the GUI and switches to editGUI no problem at all, but won't switch back
    I think I've tracked down the problem to this section of code, what am I doing wrong??? (booleans checked not the problem)
    private void layoutCentre()
              if (editgui == false)
              remove(this.textcentre);
              String s = createDisplay();
              JtextArea.setText(s);     
              Jpanel.add(JTextArea);
              add(JPanel, BorderLayout.CENTER);
              Jpanel.revalidate();
              this.repaint();
              else
                   remove(this.textcentre);
                   JPanel=new EditGUI();
                   JPanel = egui.layoutEdit();
                   add(JPanel, BorderLayout.CENTER);
                   Jpanel.revalidate();
                   this.repaint();
         }

    airomega wrote:
    Thanks everyone, I'm a noob to the forums and to Java so sorry for lack of forum etiquette. No big deal. Your etiquette was fine.
    I sorted it by separating panel creation into two classes, and checking the boolean when calling the methods instead. Still that makes two of us now who have recommended that you look into CardLayout. If you haven't done so, I suggest you do this now.

Maybe you are looking for

  • Dunning Letters and Customer Statements

    Hi All Our client does not want to send dunning letters and statements on backdated invoices for a particular site or sites. Please any clue on how to go about it? Thanks in advance. Ify

  • Suggestions for bicycle mount for iPhone 4 with case?

    I'm looking for a bicycle mount for my iPhone and I'm having no luck at all. Any suggestions for a decent one?

  • Change User Permissions

    I migrated and later I created a new profile. I then erased the original profile. I had some how in the past changed my short name to a word with a capital and i wasn't very comfortable with that . so now my profile wasn't the original on this machin

  • Elements 10 won't load correctly

    I installed Elements 10 onto my computer running Windows 7, Everything worked perfectly for a couple of weeks. I am now unable to access organiser. The programme freezes and will not allow me to import files into the catalog.I have tried the obvious

  • Abnormal termination, Error Code: C0000005 ACCESS_VIOLATION

    Hi All: I am using Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 and Developer Forms [32 Bit] Version 6.0.8.23.2. I have created a menu. When I call this menu in a form and execute this from either Form Builder or Form Run Time, form exec