디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

횽들 도와줘영 ㅜㅜ

횽들 도와줭 (124.51) 2011.12.16 16:01:22
조회 47 추천 0 댓글 2

 횽들 array의 총합을 구하려고하는데 500 + -300을 한다고 치면 답이 700으로 나오고 list 버튼을 클릭하면 결과가 한번 나오게 하고싶은데 누를때마다 숫자가 계속 바껴 ㅠ 집에서 쓸 간단한 가계부 프로그램 만드려는데.. 자바코드에여


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font;
import javax.swing.JTextArea;
import java.text.NumberFormat;

class Mainmenu extends JFrame implements ActionListener
{
    int max = 10;
    double alltotal = 0;
    String[ ] name = new String[max];
    double[ ] amount = new double[max];
    double totala = 0;
    int a = 0;    
    int b = 0;

    private static final int FRAME_WIDTH = 500;
    private static final int FRAME_HEIGHT = 500;
    private static final int FRAME_X_ORIGIN = 440;
    private static final int FRAME_Y_ORIGIN = 440;

    private static final int BUTTON_WIDTH = 80;
    private static final int BUTTON_HEIGHT = 30;

    private JButton addButton;
    private JButton deleteButton;
    private JButton listButton;
    private JButton wishlistButton;
    private JButton quitButton;
    private JButton howtouseButton;

    public static void main(String[] args) 
    {
        Mainmenu frame = new Mainmenu();
        frame.setVisible(true);
    }

    public Mainmenu ( )
    {
        setTitle ("Moneybook");
        setSize (FRAME_WIDTH, FRAME_HEIGHT);
        setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);
        contentPane.setBackground(Color.white);

        JTextArea text = new JTextArea();
        setLayout(null);
        add(text);
        text.setBounds(100, 3, 300, 100);
        Font font = new Font("Serif", Font.BOLD, 52);
        text.setFont(font);
        text.setText ("MoneyBook");

        addButton = new JButton("Add");
        addButton.setBounds(200, 120, BUTTON_WIDTH, BUTTON_HEIGHT);
        addButton.addActionListener(this);
        contentPane.add(addButton);

        deleteButton = new JButton("Delete");
        deleteButton.setBounds(200, 180, BUTTON_WIDTH, BUTTON_HEIGHT);
        deleteButton.addActionListener(this);
        contentPane.add(deleteButton);

        listButton = new JButton("List");
        listButton.setBounds(200, 240, BUTTON_WIDTH, BUTTON_HEIGHT);
        listButton.addActionListener(this);
        contentPane.add(listButton);

        wishlistButton = new JButton("Wishlist");
        wishlistButton.setBounds(200, 300, BUTTON_WIDTH, BUTTON_HEIGHT);
        wishlistButton.addActionListener(this);
        contentPane.add(wishlistButton);

        quitButton = new JButton("Quit");
        quitButton.setBounds(200, 360, BUTTON_WIDTH, BUTTON_HEIGHT);
        quitButton.addActionListener(this);
        contentPane.add(quitButton);

        howtouseButton = new JButton("How to use");
        howtouseButton.setBounds(324, 432, 160, BUTTON_HEIGHT);
        howtouseButton.addActionListener(this);
        contentPane.add(howtouseButton);
    }

    public void actionPerformed(ActionEvent event)
    {      
        for ( int i = 0; i < max; i++ )
        {
            totala += amount[i];
        }
        JButton clickedButton = (JButton) event.getSource();
        System.out.print('\f');
        if (clickedButton == addButton)
        {
            name[a] = JOptionPane.showInputDialog("Make a name for your income or outcome");
            amount[a] = Double.parseDouble(JOptionPane.showInputDialog("Enter the amount you earn or lost [State the outcome by typing - infront of number]"));
            a = a + 1;
        }

        if (clickedButton == deleteButton)
        {
            String searchName = JOptionPane.showInputDialog("Enter the name that you made for your income or outcome");
            for (int i=0; i<max; i++)
            {
                if (searchName.equals(name[i]))
                {
                    name[i] = null;
                    amount[i] = 0;
                }
            }
        }

        if (clickedButton == listButton)
        {
            for (int i=0; i<max; i++) 
            {
                if (name[i] != null)
                {
                    System.out.println("Title:"+name[i]);
                    System.out.println("Amount: $"+amount[i]);
                }
                System.out.println("Total amount:"+ totala);
            }
        }

        if (clickedButton == wishlistButton)
        {
        }

        if (clickedButton == quitButton)
        {
            JOptionPane.showMessageDialog(null, "Thank you for using Moneybook");
            System.exit(0);
        }

        if (clickedButton == howtouseButton)
        {
            JOptionPane.showMessageDialog(null, "[Moneybook]\nClick the \n*Add button to add your income or outcome status\n*Delete button to delete your income or outcome status\n*List button to list your balance\n*Wishlist button to add,delete and list your wish product.\n*Quit button to exit the program");
        }
    }
}
>

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 영포티룩도 멋지게 소화할 것 같은 40대 스타는? 운영자 25/10/27 - -
AD 저녁 뭐먹지? 오늘의 메뉴 추천! 운영자 25/10/31 - -
295083 전테일의 공개장(여러가지 생각이 드네요) 흠흠흠(116.36) 11.12.19 57 0
295082 자바 과제 대행 구합니다 [1] 정글쥬스(1.210) 11.12.19 130 0
295081 회사에 보낼 ppt 다 만들었어. [5] 좋은아버지갤로그로 이동합니다. 11.12.19 119 0
295077 처음 파이썬 공부 할려고 하는데 책 어떤게 좋을까요?? [7] 파이선(175.116) 11.12.19 216 0
295076 위로 받고 싶은 형들에게... [1] Lover♥갤로그로 이동합니다. 11.12.19 56 0
295073 혹시 동적 인프라에 대한 개념 에 대해 잘아는 형있어? 좋은아버지갤로그로 이동합니다. 11.12.19 36 0
295072 게임프로그래밍 과 CCNA에 상관관계 CHALLENGER갤로그로 이동합니다. 11.12.19 112 0
295071 이클립스 프로젝트 불러오기 질문좀... [1] 123(211.200) 11.12.19 115 0
295070 혹시 홈서버 굴리는 형들 있음? [7] 한화외야수갤로그로 이동합니다. 11.12.19 138 0
295068 야호 내일이 마지막 면접이다 ! [7] 좋은아버지갤로그로 이동합니다. 11.12.19 135 0
295067 to. 김심심 줫밥(122.49) 11.12.19 35 0
295066 주식 폭락이라며 삼양주식은 올랐다며? [5] 쿄스케갤로그로 이동합니다. 11.12.19 119 0
295065 갤탭 찾아옴 ㅇㅇ [4] 줫밥(122.49) 11.12.19 69 0
295064 오예 릭 잡았다. 천회장(14.52) 11.12.19 49 0
295062 @#$^%%@#$^ [4] 생물학(122.35) 11.12.19 73 0
295058 곽팀장♥ [5] Lover♥갤로그로 이동합니다. 11.12.19 102 0
295057 여기서질문 [12] 컴쏘갤로그로 이동합니다. 11.12.19 120 0
295056 고인 목록 [4] &gt;&lt;(220.70) 11.12.19 93 0
295054 야 근데 이 짤에 있는 사람들은 대체 뭔 생각으로 살아가고 있는거임? [5] Lover♥갤로그로 이동합니다. 11.12.19 205 0
295053 조는거 딴짓하는거에 머 그리 예민하게 구는지 모르겠다...? [3] ㅅㄱㅅㄱㅅㄱ갤로그로 이동합니다. 11.12.19 82 0
295052 오늘 평소랑 좀 다르게 출근했는데 [1] McHello갤로그로 이동합니다. 11.12.19 84 0
295051 미국에서 [5] 컴쏘갤로그로 이동합니다. 11.12.19 90 0
295047 자바 코드 좀 봤는데 어렵네;; [7] 줫밥(122.49) 11.12.19 124 0
295046 난 목표가 연봉 5000인데 [3] ㅇㅇ(125.182) 11.12.19 196 0
295045 공부 할게 산더미인데 김정일 죽어서 일하기 싫다 [1] 개심심(61.73) 11.12.19 77 0
295044 C언어에서는 디폴트 매개변수 어떻게 쓰나요; [3] 치킨맛맛폰갤로그로 이동합니다. 11.12.19 99 0
295043 카톡 닉네임 김센스 게이있냐? 줫밥(122.49) 11.12.19 54 0
295039 어깨가 아프고... [2] 9m(203.236) 11.12.19 46 0
295035 연봉 얼마 받고 싶냐. [7] ㅂㅎㅅ(124.35) 11.12.19 158 0
295034 환급 100만원 이야? [1] 신입사원갤로그로 이동합니다. 11.12.19 59 0
295032 to. 케닭 [11] 줫밥(122.49) 11.12.19 155 0
295031 레알 OpenGL 아는 횽 하나도 업음?? [2] 신입사원갤로그로 이동합니다. 11.12.19 91 0
295030 야 이거좀 갈켜줘 [25] 줫밥(122.49) 11.12.19 180 0
295029 소스입니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 55 0
295028 선배님들 질문있습니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 75 0
295026 대한민국코더 인사드립니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 63 0
295024 주식 박살났다 ㅋㅋㅋ 김정일 시발년 뒤져도 씨발년 살아도 씨발년 [2] 개심심(61.73) 11.12.19 121 0
295023 양재동쪽에 스포츠 가르쳐주는 곳 없나? 배드민턴이라던지 뭐든지.. [5] 초딩6(59.13) 11.12.19 302 3
295022 입사한 이후로 공휴일이 없다 3(121.169) 11.12.19 55 0
295021 김정일 죽었는데 [1] Adelposs갤로그로 이동합니다. 11.12.19 91 0
295018 안드로이드 면접 질문 구걸좀용 ^^; [13] 흐잌ㅋ(119.65) 11.12.19 612 0
295015 이번주 정모하자 [2] 줫밥(122.49) 11.12.19 87 0
295012 윈도우 xp 발매전 마소 직원의 대담함.jpg Stan(220.244) 11.12.19 171 0
295011 유용한 글이니 잘 읽어보고 GC를 쓰도록 하자 [1] 퓨리님(111.91) 11.12.19 71 0
295010 손들어!! 움직이지마 그리고 가진돈 다내놔!.jpg Stan(220.244) 11.12.19 56 0
295009 횽아들.올만이내요 저ㅜ내일임대합니다 [5] 푸른명월갤로그로 이동합니다. 11.12.19 62 1
295008 아까 질문했던 사람인데염 초보자(211.211) 11.12.19 31 0
295007 똒똒똒!~!! 계세요? 똑똒! [2] Stan(220.244) 11.12.19 50 0
295006 흔한 웹디자이너.jpg Stan(220.244) 11.12.19 128 0
295003 가장 훌륭한 디버거는 [1] 천회장(14.52) 11.12.19 73 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2