Search Results

Search found 13 results on 1 pages for 'terence6'.

Page 1/1 | 1 

  • Converting app to MVC and running it in both console and gui

    - by terence6
    I have a simple java gui calculator, with 3 number systems (there are some bugs but that doesn't matter now). Currently all code is in one file. My task is to rewrite it as MVC, and add possibility to run it in either gui or console mode. How should I divide this program to organise it as M-V-C ? Is it written properly enough to add console functionality to it? (guess I'll have to change all methods invoking to JLabel Output to something simply storing an output String as a model argument and then having View to get it). Here's the starting code : http://paste.pocoo.org/show/224566/ Here's what I already have : Main : http://paste.pocoo.org/show/224567/ Model : http://paste.pocoo.org/show/224570/ View : http://paste.pocoo.org/show/224569/ Controller : http://paste.pocoo.org/show/224568/ I don't have view in my model so I can't call to Output. That's the first problem I can see.

    Read the article

  • Custom buttons in MS-Access 2k7

    - by terence6
    I'm adding some custom buttons to my forms in MS Access, but somehow I can't make them work. In buttons properties Event tab I've changed 'On Click' event to call 'Event procedure'. Then in VBasic I'm selecting my button and from what I know this code should give me prompt, and if Yos is selected the form should close. But when I click my buttons simply nothing happens. Am I doing something wrong ? Option Compare Database Option Explicit Private Sub cmdQuitApp_Click() If MsgBox("Are you sure you want to close the form?", vbYesNo + vbQuestion + vbInformation, "Clasing the form.") = vbYes Then DoCmd.Close End If End Sub

    Read the article

  • Beginning with event listeners

    - by terence6
    I have a simple app, showing picture made of tiled images(named u1, u2,...,u16.jpg). Now I'd like to add some Events to it, so that I can show these images only when proper button is clicked. I've tried doing it on my own, but it's not working. Where am I doing something wrong? Original code : import java.awt.GridLayout; import javax.swing.*; import javax.swing.border.BevelBorder; public class Tiles_2 { public static void main(String[] args) { final JFrame f = new JFrame("Usmiech"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); JLabel l = new JLabel(); for (int i = 1; i < 17; i++) { String path = "u"+ i+".jpg"; l = new JLabel(new ImageIcon(path)); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); panel.add(l); } f.setContentPane(panel); f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } } New code : import java.awt.GridLayout; import javax.swing.*; import javax.swing.border.BevelBorder; import java.awt.event.*; public class Zad_8_1 implements ActionListener { public void actionPerformed(ActionEvent e) { JButton b = (JButton)(e.getSource()); String i = b.getText(); b = new JButton(new ImageIcon("u"+i+".jpg")); } public static void main(String[] args) { final JFrame f = new JFrame("Smile"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); JButton l = null; for (int i = 1; i < 17; i++) { String path = "u"+ i+".jpg"; l = new JButton(""+i); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); l.setSize(53,53); panel.add(l); } f.setContentPane(panel); f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } } This should work like this : http://img535.imageshack.us/img535/3129/lab8a.jpg

    Read the article

  • Formula to draw pyramid of circles

    - by terence6
    I'm trying to create a pyramid of circles to my game, looking similar to this : But I can't make it print properly. Constantly I'm getting really strange spirals but nothing close to this. Can anyone give me some tip on proper formula ? My window is 600x600, base of pyramid is 8 . fields = new Field[BASE*(BASE/2)+4]; int line_count = BASE; int line_tmp = line_count; for(int i=0; i< fields.length; i++){ for( int j=line_tmp; j <= line_count; j++){ fields[i] = new Field(0, (150+(line_tmp*5)),(600+line_tmp*5)); } line_count--; line_tmp = line_count; }

    Read the article

  • How to print all values of Vector[]

    - by terence6
    I have a Vector[] of Object type that stores my data. How to print all it's objects ? The code: private static Vector<Object[]> vector = new Vector<Object[]>(); int event=0; for(int i=0; i<10; i++){ vector.add( this.addToObject(System.currentTimeMillis(), event , "String") ); event++; } private Object[] addToObject(long t, int i,String s ){ Object[] o = new Object[4]; o[3] = s; o[2] = i; o[1] = "00000"; o[0] = t; return o; } printing public static void main(String[]args){ main m = new Main(); for(int i=0; i< m.vector.size(); i++){ } } And I'd like to get sth like this : 1202393057117 1 OOOOO String 1202393057117 2 OOOOO String 1202393057118 3 OOOOO String 1202393057118 4 OOOOO String 1202393057118 5 OOOOO String

    Read the article

  • Filtering forms in MS Access

    - by terence6
    I have a simple form showing products from my database. Each product has a foreign key to manufacturer_id . I would like to filter my form by manufacturer_id instead of default product_id. How I can do that ? I know I must create a macro. Also I've already created a query, that takes manufacturer's name as argument and returns manufacturer_id. So basically it should work in this way, that when I press 'Filter' button on my form, it runs macro that opens my query asking for manufacturer's name. And when the name is returned the whole form is filtered (so somewhere there should be comparison between manufacturer_id in product and that returned from query, but I can't manage to do that). I'm using access 2007. Model:

    Read the article

  • Cnoverting application to MVC architecture

    - by terence6
    I'm practicing writing MVC applications. I have a Mastermind game, that I would like to rewrite as MVC app. I have divided my code to parts, but instead of working game I'm getting empty Frame and an error in "public void paint( Graphics g )". Error comes from calling this method in my view with null argument. But how to overcome this ? MVC was quite simple with swing but awt and it's paint methods are much more complicated. Code of working app : http://paste.pocoo.org/show/224982/ App divided to MVC : Main : public class Main { public static void main(String[] args){ Model model = new Model(); View view = new View("Mastermind", 400, 590, model); Controller controller = new Controller(model, view); view.setVisible(true); } } Controller : import java.awt.*; import java.awt.event.*; public class Controller implements MouseListener, ActionListener { private Model model; private View view; public Controller(Model m, View v){ model = m; view = v; view.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); view.addMouseListener(this); } public void actionPerformed( ActionEvent e ) { if(e.getSource() == view.checkAnswer){ if(model.isRowFull){ model.check(); } } } public void mousePressed(MouseEvent e) { Point mouse = new Point(); mouse = e.getPoint(); if (model.isPlaying){ if (mouse.x > 350) { int button = 1 + (int)((mouse.y - 32) / 50); if ((button >= 1) && (button <= 5)){ model.fillHole(button); } } } } public void mouseClicked(MouseEvent e) {} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} } View : import java.awt.*; import javax.swing.*; import java.awt.event.*; public class View extends Frame implements ActionListener { Model model; JButton checkAnswer; private JPanel button; static final int HIT_X[] = {270,290,310,290,310}, HIT_Y[] = {506,496,496,516,516}; public View(String name, int w, int h, Model m){ model = m; setTitle( name ); setSize( w,h ); setResizable( false ); this.setLayout(new BorderLayout()); button = new JPanel(); button.setSize( new Dimension(400, 100)); button.setVisible(true); checkAnswer = new JButton("Check"); checkAnswer.addActionListener(this); checkAnswer.setSize( new Dimension(200, 30)); button.add( checkAnswer ); this.add( button, BorderLayout.SOUTH); button.setVisible(true); for ( int i=0; i < model.SCORE; i++ ){ for ( int j = 0; j < model.LINE; j++ ){ model.pins[i][j] = new Pin(20,0); model.pins[i][j].setPosition(j*50+30,510-i*50); model.pins[i+model.SCORE][j] = new Pin(8,0); model.pins[i+model.SCORE][j].setPosition(HIT_X[j],HIT_Y[j]-i*50); } } for ( int i=0; i < model.LINE; i++ ){ model.pins[model.OPTIONS][i] = new Pin( 20, i+2 ); model.pins[model.OPTIONS][i].setPosition( 370,i * 50 + 56); } model.combination(); model.paint(null); } public void actionPerformed( ActionEvent e ) { } } Model: import java.awt.*; public class Model extends Frame{ static final int LINE = 5, SCORE = 10, OPTIONS = 20; Pin pins[][] = new Pin[21][LINE]; int combination[] = new int[LINE]; int curPin = 0; int turn = 1; int repaintPin; boolean isUpdate = true, isPlaying = true, isRowFull = false; public Model(){ } void fillHole(int color) { pins[turn-1][curPin].setColor(color+1); repaintPins( turn ); curPin = (curPin+1) % LINE; if (curPin == 0){ isRowFull = true; } } public void paint( Graphics g ) { g.setColor( new Color(238, 238, 238)); g.fillRect( 0,0,400,590); for ( int i=0; i < pins.length; i++ ) { pins[i][0].paint(g); pins[i][1].paint(g); pins[i][2].paint(g); pins[i][3].paint(g); pins[i][4].paint(g); } } public void update( Graphics g ) { if ( isUpdate ) { paint(g); } else { isUpdate = true; pins[repaintPin-1][0].paint(g); pins[repaintPin-1][1].paint(g); pins[repaintPin-1][2].paint(g); pins[repaintPin-1][3].paint(g); pins[repaintPin-1][4].paint(g); } } void repaintPins( int pin ) { repaintPin = pin; isUpdate = false; repaint(); } void check() { int junkPegs[] = new int[LINE], junkCode[] = new int[LINE]; int pegCount = 0, pico = 0; for ( int i = 0; i < LINE; i++ ) { junkPegs[i] = pins[turn-1][i].getColor(); junkCode[i] = combination[i]; } for ( int i = 0; i < LINE; i++ ){ if (junkPegs[i]==junkCode[i]) { pins[turn+SCORE][pegCount].setColor(1); pegCount++; pico++; junkPegs[i] = 98; junkCode[i] = 99; } } for ( int i = 0; i < LINE; i++ ){ for ( int j = 0; j < LINE; j++ ) if (junkPegs[i]==junkCode[j]) { pins[turn+SCORE][pegCount].setColor(2); pegCount++; junkPegs[i] = 98; junkCode[j] = 99; j = LINE; } } repaintPins( turn+SCORE ); if ( pico == LINE ){ isPlaying = false; } else if ( turn >= 10 ){ isPlaying = false; } else{ curPin = 0; isRowFull = false; turn++; } } void combination() { for ( int i = 0; i < LINE; i++ ){ combination[i] = 1 + (int)(Math.random()*5); System.out.print(i+","); } } } class Pin{ private int color, X, Y, radius; private static final Color COLORS[] = { Color.black, Color.white, Color.red, Color.yellow, Color.green, Color.blue, new Color(7, 254, 250)}; public Pin(){ X = 0; Y = 0; radius = 0; color = 0; } public Pin( int r,int c ){ X = 0; Y = 0; radius = r; color = c; } public void paint( Graphics g ){ int x = X-radius; int y = Y-radius; if (color > 0){ g.setColor( COLORS[color]); g.fillOval( x,y,2*radius,2*radius ); } else{ g.setColor( new Color(238, 238, 238) ); g.drawOval( x,y,2*radius-1,2*radius-1 ); } g.setColor( Color.black ); g.drawOval( x,y,2*radius,2*radius ); } public void setPosition( int x,int y ){ this.X = x ; this.Y = y ; } public void setColor( int c ){ color = c; } public int getColor() { return color; } } Any clues on how to overcome this would be great. Have I divided my code improperly ?

    Read the article

  • How to display panels with component in frame

    - by terence6
    Why my JFrame 'frame' is diplaying empty window, when it should give me 3 menu buttons and my own painted JComponent below ? What am I missing here ? import java.awt.*; import javax.swing.*; public class Eyes extends JFrame { public static void main(String[] args) { final JFrame frame = new JFrame("Eyes"); frame.setPreferredSize(new Dimension(450, 300)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel players = new JPanel(new GridLayout(1, 3)); players.add(new JButton("Eyes color")); players.add(new JButton("Eye pupil")); players.add(new JButton("Background color")); JPanel eyes = new JPanel(); eyes.add(new MyComponent()); JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(players); content.add(eyes); frame.getContentPane(); frame.pack(); frame.setVisible(true); } } class MyComponent extends JComponent { public MyComponent(){ } @Override public void paint(Graphics g) { int height = 120; int width = 120; Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); BasicStroke bs = new BasicStroke(3.0f); g2d.setStroke(bs); g2d.setColor(Color.yellow); g2d.fillOval(200, 200, height, width); g2d.setColor(Color.black); g2d.drawOval(60, 60, height, width); } }

    Read the article

  • C++ pointers on example

    - by terence6
    I have a sample code : #include <iostream> #include <conio.h> using namespace std; int main () { int firstvalue = 5, secondvalue = 15; int * p1, * p2; p1 = &firstvalue; p2 = &secondvalue; cout << "1.p1: " << p1 << ", p2: " << p2 << endl; cout << "1.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 10; cout << "2.p1: " << p1 << ", p2: " << p2 << endl; cout << "2.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p2 = *p1; cout << "3.p1: " << p1 << ", p2: " << p2 << endl; cout << "3.*p1: " << *p1 << ", *p2: " << *p2 << endl; p1 = p2; cout << "4.p1: " << p1 << ", p2: " << p2 << endl; cout << "4.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 20; cout << "5.p1: " << p1 << ", p2: " << p2 << endl; cout << "5.*p1: " << *p1 << ", *p2: " << *p2 << endl; cout << "firstvalue is " << firstvalue << endl; cout << "secondvalue is " << secondvalue << endl; cout << "firstvalue is " << &firstvalue << endl; cout << "secondvalue is " << &secondvalue << endl; getch(); return 0; } And here's the output : 1.p1: 0041FB40, p2: 0041FB34 1.*p1: 5, *p2: 15 2.p1: 0041FB40, p2: 0041FB34 2.*p1: 10, *p2: 15 3.p1: 0041FB40, p2: 0041FB34 3.*p1: 10, *p2: 10 4.p1: 0041FB34, p2: 0041FB34 4.*p1: 10, *p2: 10 5.p1: 0041FB34, p2: 0041FB34 5.*p1: 20, *p2: 20 firstvalue is 10 secondvalue is 20 firstvalue is 0041FB40 secondvalue is 0041FB34 What is copied in the line "p1 = p2" ? Does p1 become reference to p2 or does it work in different way ?

    Read the article

  • Converting application to MVC architecture

    - by terence6
    I'm practicing writing MVC applications. I have a Mastermind game, that I would like to rewrite as MVC app. I have divided my code to parts, but instead of working game I'm getting empty Frame and an error in "public void paint( Graphics g )". Error comes from calling this method in my view with null argument. But how to overcome this ? MVC was quite simple with swing but awt and it's paint methods are much more complicated. Code of working app : http://paste.pocoo.org/show/224982/ App divided to MVC : Main : public class Main { public static void main(String[] args){ Model model = new Model(); View view = new View("Mastermind", 400, 590, model); Controller controller = new Controller(model, view); view.setVisible(true); } } Controller : import java.awt.*; import java.awt.event.*; public class Controller implements MouseListener, ActionListener { private Model model; private View view; public Controller(Model m, View v){ model = m; view = v; view.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); view.addMouseListener(this); } public void actionPerformed( ActionEvent e ) { if(e.getSource() == view.checkAnswer){ if(model.isRowFull){ model.check(); } } } public void mousePressed(MouseEvent e) { Point mouse = new Point(); mouse = e.getPoint(); if (model.isPlaying){ if (mouse.x > 350) { int button = 1 + (int)((mouse.y - 32) / 50); if ((button >= 1) && (button <= 5)){ model.fillHole(button); } } } } public void mouseClicked(MouseEvent e) {} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} } View : import java.awt.*; import javax.swing.*; import java.awt.event.*; public class View extends Frame implements ActionListener { Model model; JButton checkAnswer; private JPanel button; static final int HIT_X[] = {270,290,310,290,310}, HIT_Y[] = {506,496,496,516,516}; public View(String name, int w, int h, Model m){ model = m; setTitle( name ); setSize( w,h ); setResizable( false ); this.setLayout(new BorderLayout()); button = new JPanel(); button.setSize( new Dimension(400, 100)); button.setVisible(true); checkAnswer = new JButton("Check"); checkAnswer.addActionListener(this); checkAnswer.setSize( new Dimension(200, 30)); button.add( checkAnswer ); this.add( button, BorderLayout.SOUTH); button.setVisible(true); for ( int i=0; i < model.SCORE; i++ ){ for ( int j = 0; j < model.LINE; j++ ){ model.pins[i][j] = new Pin(20,0); model.pins[i][j].setPosition(j*50+30,510-i*50); model.pins[i+model.SCORE][j] = new Pin(8,0); model.pins[i+model.SCORE][j].setPosition(HIT_X[j],HIT_Y[j]-i*50); } } for ( int i=0; i < model.LINE; i++ ){ model.pins[model.OPTIONS][i] = new Pin( 20, i+2 ); model.pins[model.OPTIONS][i].setPosition( 370,i * 50 + 56); } model.combination(); model.paint(null); } public void actionPerformed( ActionEvent e ) { } } Model: import java.awt.*; public class Model extends Frame{ static final int LINE = 5, SCORE = 10, OPTIONS = 20; Pin pins[][] = new Pin[21][LINE]; int combination[] = new int[LINE]; int curPin = 0; int turn = 1; int repaintPin; boolean isUpdate = true, isPlaying = true, isRowFull = false; public Model(){ } void fillHole(int color) { pins[turn-1][curPin].setColor(color+1); repaintPins( turn ); curPin = (curPin+1) % LINE; if (curPin == 0){ isRowFull = true; } } public void paint( Graphics g ) { g.setColor( new Color(238, 238, 238)); g.fillRect( 0,0,400,590); for ( int i=0; i < pins.length; i++ ) { pins[i][0].paint(g); pins[i][1].paint(g); pins[i][2].paint(g); pins[i][3].paint(g); pins[i][4].paint(g); } } public void update( Graphics g ) { if ( isUpdate ) { paint(g); } else { isUpdate = true; pins[repaintPin-1][0].paint(g); pins[repaintPin-1][1].paint(g); pins[repaintPin-1][2].paint(g); pins[repaintPin-1][3].paint(g); pins[repaintPin-1][4].paint(g); } } void repaintPins( int pin ) { repaintPin = pin; isUpdate = false; repaint(); } void check() { int junkPegs[] = new int[LINE], junkCode[] = new int[LINE]; int pegCount = 0, pico = 0; for ( int i = 0; i < LINE; i++ ) { junkPegs[i] = pins[turn-1][i].getColor(); junkCode[i] = combination[i]; } for ( int i = 0; i < LINE; i++ ){ if (junkPegs[i]==junkCode[i]) { pins[turn+SCORE][pegCount].setColor(1); pegCount++; pico++; junkPegs[i] = 98; junkCode[i] = 99; } } for ( int i = 0; i < LINE; i++ ){ for ( int j = 0; j < LINE; j++ ) if (junkPegs[i]==junkCode[j]) { pins[turn+SCORE][pegCount].setColor(2); pegCount++; junkPegs[i] = 98; junkCode[j] = 99; j = LINE; } } repaintPins( turn+SCORE ); if ( pico == LINE ){ isPlaying = false; } else if ( turn >= 10 ){ isPlaying = false; } else{ curPin = 0; isRowFull = false; turn++; } } void combination() { for ( int i = 0; i < LINE; i++ ){ combination[i] = 1 + (int)(Math.random()*5); System.out.print(i+","); } } } class Pin{ private int color, X, Y, radius; private static final Color COLORS[] = { Color.black, Color.white, Color.red, Color.yellow, Color.green, Color.blue, new Color(7, 254, 250)}; public Pin(){ X = 0; Y = 0; radius = 0; color = 0; } public Pin( int r,int c ){ X = 0; Y = 0; radius = r; color = c; } public void paint( Graphics g ){ int x = X-radius; int y = Y-radius; if (color > 0){ g.setColor( COLORS[color]); g.fillOval( x,y,2*radius,2*radius ); } else{ g.setColor( new Color(238, 238, 238) ); g.drawOval( x,y,2*radius-1,2*radius-1 ); } g.setColor( Color.black ); g.drawOval( x,y,2*radius,2*radius ); } public void setPosition( int x,int y ){ this.X = x ; this.Y = y ; } public void setColor( int c ){ color = c; } public int getColor() { return color; } } Any clues on how to overcome this would be great. Have I divided my code improperly ?

    Read the article

  • CASE + IF MysQL query

    - by terence6
    Problem is as follows. I have a product that can be in one of three categories (defined by category_id). Each category table has category_id field related to category_id in product table. So I have 3 cases. I'm checking If my product.category_id is in table one. If yes, I take some values. If not I check in tables that are left. What can I write In the ELSE section? Can anyone correct my query ? CASE WHEN IF EXISTS(SELECT * FROM table1 WHERE category_id='category_id') THEN SELECT type_id FROM table1 WHERE category_id='category_id'; WHEN IF EXISTS(SELECT * FROM table2 WHERE category_id='category_id') THEN SELECT value_id FROM table2 WHERE category_id='category_id'; WHEN IF EXISTS(SELECT * FROM table3 WHERE category_id='category_id') THEN SELECT group_id FROM table3 WHERE category_id='category_id'; ELSE "dont know what here"; END;

    Read the article

  • Calculate value from two field in third field

    - by terence6
    I'm trying to create a query, that will calculate sum of products on invoice. I have 3 tables : Product (with product's price) Invoice (with invoice id) Products on invoice (with invoice id, product id and number of particular products) So in my query I take invoice_id (from invoice), price (from product),number of products sold and invoice_id (from products on invoice) and calculate their product in fourth column. I know I sohuld use 'Totals' but how to achieve that ? Model:

    Read the article

1