디시인사이드 갤러리

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

갤러리 본문 영역

횽들 도와줘영 ㅜㅜ

횽들 도와줭 (124.51) 2011.12.16 16:01:22
조회 58 추천 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
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 뛰어난 운동 신경으로 남자와 싸워도 이길 것 같은 여자 스타는? 운영자 25/11/24 - -
이슈 [디시人터뷰] 충무로가 주목하는 신예, '세계의 주인' 서수빈 운영자 25/11/24 - -
AD 대학생 필수템! What's in my Bag 운영자 25/11/21 - -
295062 @#$^%%@#$^ [4] 생물학(122.35) 11.12.19 92 0
295058 곽팀장♥ [5] Lover♥갤로그로 이동합니다. 11.12.19 115 0
295057 여기서질문 [12] 컴쏘갤로그로 이동합니다. 11.12.19 137 0
295056 고인 목록 [4] &gt;&lt;(220.70) 11.12.19 108 0
295054 야 근데 이 짤에 있는 사람들은 대체 뭔 생각으로 살아가고 있는거임? [5] Lover♥갤로그로 이동합니다. 11.12.19 226 0
295053 조는거 딴짓하는거에 머 그리 예민하게 구는지 모르겠다...? [3] ㅅㄱㅅㄱㅅㄱ갤로그로 이동합니다. 11.12.19 98 0
295052 오늘 평소랑 좀 다르게 출근했는데 [1] McHello갤로그로 이동합니다. 11.12.19 104 0
295051 미국에서 [5] 컴쏘갤로그로 이동합니다. 11.12.19 105 0
295047 자바 코드 좀 봤는데 어렵네;; [7] 줫밥(122.49) 11.12.19 136 0
295046 난 목표가 연봉 5000인데 [3] ㅇㅇ(125.182) 11.12.19 212 0
295045 공부 할게 산더미인데 김정일 죽어서 일하기 싫다 [1] 개심심(61.73) 11.12.19 96 0
295044 C언어에서는 디폴트 매개변수 어떻게 쓰나요; [3] 치킨맛맛폰갤로그로 이동합니다. 11.12.19 116 0
295043 카톡 닉네임 김센스 게이있냐? 줫밥(122.49) 11.12.19 70 0
295039 어깨가 아프고... [2] 9m(203.236) 11.12.19 57 0
295035 연봉 얼마 받고 싶냐. [7] ㅂㅎㅅ(124.35) 11.12.19 173 0
295034 환급 100만원 이야? [1] 신입사원갤로그로 이동합니다. 11.12.19 81 0
295032 to. 케닭 [11] 줫밥(122.49) 11.12.19 172 0
295031 레알 OpenGL 아는 횽 하나도 업음?? [2] 신입사원갤로그로 이동합니다. 11.12.19 107 0
295030 야 이거좀 갈켜줘 [25] 줫밥(122.49) 11.12.19 201 0
295029 소스입니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 72 0
295028 선배님들 질문있습니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 88 0
295026 대한민국코더 인사드립니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 79 0
295024 주식 박살났다 ㅋㅋㅋ 김정일 시발년 뒤져도 씨발년 살아도 씨발년 [2] 개심심(61.73) 11.12.19 137 0
295023 양재동쪽에 스포츠 가르쳐주는 곳 없나? 배드민턴이라던지 뭐든지.. [5] 초딩6(59.13) 11.12.19 322 3
295022 입사한 이후로 공휴일이 없다 3(121.169) 11.12.19 69 0
295021 김정일 죽었는데 [1] Adelposs갤로그로 이동합니다. 11.12.19 105 0
295018 안드로이드 면접 질문 구걸좀용 ^^; [13] 흐잌ㅋ(119.65) 11.12.19 628 0
295015 이번주 정모하자 [2] 줫밥(122.49) 11.12.19 107 0
295012 윈도우 xp 발매전 마소 직원의 대담함.jpg Stan(220.244) 11.12.19 186 0
295011 유용한 글이니 잘 읽어보고 GC를 쓰도록 하자 [1] 퓨리님(111.91) 11.12.19 88 0
295010 손들어!! 움직이지마 그리고 가진돈 다내놔!.jpg Stan(220.244) 11.12.19 73 0
295009 횽아들.올만이내요 저ㅜ내일임대합니다 [5] 푸른명월갤로그로 이동합니다. 11.12.19 77 1
295008 아까 질문했던 사람인데염 초보자(211.211) 11.12.19 51 0
295007 똒똒똒!~!! 계세요? 똑똒! [2] Stan(220.244) 11.12.19 66 0
295006 흔한 웹디자이너.jpg Stan(220.244) 11.12.19 134 0
295003 가장 훌륭한 디버거는 [1] 천회장(14.52) 11.12.19 92 0
295000 살이 찌긴 존나 많이 쪘네 [1] 줫밥(122.49) 11.12.19 96 0
294995 이산수학 공부하려는데 책 추천좀 해줘요 [4] ㅁㄴㅇ(119.201) 11.12.19 182 0
294994 내일 말해야하는데 그만둬야 한다고..근데 타이밍이 안 좋다.. [4] 므해?갤로그로 이동합니다. 11.12.19 114 0
294993 키위다! [3] 9m(203.236) 11.12.19 86 0
294992 찾았다!!!!!!!!!!! [3] 줫밥(122.49) 11.12.19 86 0
294991 안녕하세여 자바 과제중인데 해결이 안돼서 ㅜㅜ.. [1] 초심자(211.211) 11.12.19 95 0
294989 . _ . 할게 없음 [4] 9m(203.236) 11.12.19 92 0
294988 dk tnlㄴㄹ흐ㅏㄴㄹ아ㅡㅇㄴ라ㅡ 슈발!!!!!!!!!!!!!!!!!!! [3] 줫밥(122.49) 11.12.19 71 0
294986 코딩중 오타의심이 판단되면 비프음이 울리는 에디터 [6] ㅂㅈㄷ(210.178) 11.12.19 149 0
294985 인턴은 원래 빡세게 시킴? [12] Mihark(219.239) 11.12.19 217 1
294983 웹 접근성 프로젝트 해본사람???? [8] 개심심(61.73) 11.12.19 115 1
294982 첫출근을 했는데 [8] ㅇㅇㅋ(121.140) 11.12.19 119 1
294981 횽들 질문 하나만 할께 인턴갤로그로 이동합니다. 11.12.19 44 0
294980 to. 쿄스케 [3] 줫밥(122.49) 11.12.19 62 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2