is it typical for the listener to seem to refresh very slowly... or like, inconsistently?
It doesn't really register all my clicks, especially if I click quickly (not that it matters for my project)
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Deleted User 3420
24492 Posts
December 22 2016 01:59 GMT
#16361
is it typical for the listener to seem to refresh very slowly... or like, inconsistently? It doesn't really register all my clicks, especially if I click quickly (not that it matters for my project) | ||
Manit0u
Poland17187 Posts
December 22 2016 02:32 GMT
#16362
On December 22 2016 10:59 travis wrote: cool, got it working is it typical for the listener to seem to refresh very slowly... or like, inconsistently? It doesn't really register all my clicks, especially if I click quickly (not that it matters for my project) Next time try using the language without garbage collector ![]() | ||
Blisse
Canada3710 Posts
December 22 2016 04:04 GMT
#16363
| ||
Deleted User 3420
24492 Posts
December 22 2016 04:09 GMT
#16364
the issue was that I was using mouseclicked, which needs the mouse to be fully released, and that's apparently more sensitive than I realized using mousepressed makes me able to draw circles very rapidly | ||
RoomOfMush
1296 Posts
December 22 2016 08:46 GMT
#16365
On December 22 2016 13:09 travis wrote: ah yeah the issue was that I was using mouseclicked, which needs the mouse to be fully released, and that's apparently more sensitive than I realized using mousepressed makes me able to draw circles very rapidly The exact behaviour of mouseClicked depends on the operating system used. In general though it only registers if the mouse is pressed down and then released while staying roughly on the same spot on screen. If you press the mouse down, move it, and then release it will usually not count as a mouseClicked event. If you use mousePressed instead the behaviour is not platform dependent and you can build it the way you like. On December 22 2016 11:32 Manit0u wrote: Show nested quote + On December 22 2016 10:59 travis wrote: cool, got it working is it typical for the listener to seem to refresh very slowly... or like, inconsistently? It doesn't really register all my clicks, especially if I click quickly (not that it matters for my project) Next time try using the language without garbage collector ![]() I hope you know that what you are saying is bullshit and your post was in jest, but just in case: GarbageCollection has nothing to do with that. The default GarbageCollector (GC) runs in a background task and is inactive in most cases. For most applications like the one travis is building the GC shouldnt even be noticeable when doing work. Even if it was actually noticeable that wouldnt result in missed inputs but rather delayed response times. These usually manifest as lag spikes though rather than constant delays. | ||
Manit0u
Poland17187 Posts
December 22 2016 11:22 GMT
#16366
![]() | ||
phar
United States1080 Posts
December 22 2016 17:17 GMT
#16367
On December 22 2016 06:04 mantequilla wrote: Show nested quote + On December 22 2016 02:15 phar wrote: The generic tech for converting a digital signal to audio is a DAC, and to sound it's, well, it's called a speaker, but you probably already knew that. Here's a simple ish guide: https://www.google.com/amp/www.instructables.com/id/Arduino-Basics-Making-Sound/?amp_page=true?client=ms-android-google Ahh fucking AMP links sorry. Let me know if I'm misunderstanding something about your question. noo noo I won't be making sound using arduino ![]() it will be like this microphone circuit sends analog signal to arduino arduino processes it if necessary and sends data over lan to my pc a program on my pc will play the sound I'm only asking about the first part (listening to sound). Rest I can figure out. OK gotcha. Well the reverse side of it you already have half of (microphone). The opposite of a DAC is an ADC, and Arduino probably had one built in. Likely all you're missing is some circuitry in the middle, maybe some op amps, resistors, etc to get enough gain. If you don't need anything fancy for clipping or what not, it should be not too hard. A basic op amp circuit to make 10-100-1000x gain is like first year EE lab stuff. Here's some potential starting points: http://electronics.stackexchange.com/questions/16595/how-to-make-a-clean-amplified-microphone-analog-to-digital-conversion I would guess it's also possible to use a transistor to get gain, though I'm less confident about that approach: http://electronics.stackexchange.com/questions/36795/using-a-microphone-with-an-arduino Last tip, software-wise. If you're using the built in ADC on the Arduino, idk if there's libraries to do all the sampling for you, or if you need to build that all from scratch. If you do need to build it from scratch, then you need to have some reasonable RTC (real time computing) logic built up. That is, you're gonna want to be sampling your analog signal very frequently and very regularly (however many samples per second, at a regular interval). You probably need good timing and interrupt logic there (though I've only had to do this stuff in more low level MCs, so maybe it's easier in Arduino). | ||
Deleted User 3420
24492 Posts
December 22 2016 17:30 GMT
#16368
the idea is I just wanted to mess around with the traveling salesman problem. But I wanted a reasonable way to input nodes so my plan is to have this clickable graph, and each time a node is added (graph is clicked), the x and y coordinate of that node is stored. Using that information I will be able to get the "weight" (distance) between 2 nodes using pythagorean theorem. Then I will have this handy gui to display the results of any algorithms that are ran. so, mush, I took what you gave me and made some small changes to suit my needs, then added a couple buttons to run the algorithms, and made a line appear to show the path of node insertion (just find it visually appealing). is it correct for me to add my buttons to the jframe? + Show Spoiler +
| ||
Neshapotamus
United States163 Posts
December 22 2016 17:36 GMT
#16369
| ||
Deleted User 3420
24492 Posts
December 22 2016 17:41 GMT
#16370
I think I am getting some sort of book on python around christmas and I might start some other book soon too but I figured until then this might be a fun project | ||
RoomOfMush
1296 Posts
December 22 2016 17:54 GMT
#16371
There are a few odd things with your code: 1) Why do you create a new ClickPanel each time the mouse is pressed? You just create it and then throw it away. Just remove that line. 2) Why is your field "nodes" static? That looks like a major source for potential bugs in the future. Remove that static keyword. 3) Although it works to store a List of Lists with each inner List having exactly 2 Integer elements it really isnt a "nice" way of doing things. Why not use the Point class as mentioned by Blisse. 4) The fields "x" and "y" arent really needed either. They are only ever used like local variables. Get rid of them. 5) Your ActionListener's can be converted to Lambda-Expressions for better readability. But this is more personal preference rather than objective improvement. 6) Your paintComponent method works, but it could be slightly improved. Right now you are iterating your nodes List twice. You can do all the drawing with only 1 iteration. Here is an improved version which takes the above mentioned points into account: + Show Spoiler + import java.awt.Color; and lastly: 7) Adding your buttons directly to the JPanel might not give you the results you are looking for. In Swing you are supposed to use LayoutManagers to position components on screen. By default a JPanel uses the FlowLayout as its layout. This is why your JButtons appear next to each other at the top of the JFrame. Thats the default behaviour of the FlowLayout. If this is enough for your needs you can continue doing it this way. At some point in the future you will probably want to use a more sophisticated GUI and you will need to use nested JPanels with different LayoutManagers. People rarely build this by hand. The most common approach is to use a tool to help you build your GUI. The WindowBuilder of Eclipse (its a plugin) works rather well with Swing. It has a few bugs and it has its limitations but for simple GUI's is more than enough. Other IDE's also have their own Swing Editors but I dont know them all that well. | ||
Neshapotamus
United States163 Posts
December 22 2016 18:00 GMT
#16372
Here is my reasoning 1. It's easily shareable 2. Html and javascript are used much more in the real world than java UI applications 3. You're most likely going to learn it anyways 4. It's much easier to write it in a framework that is designed for visualizations. 5. You will get much more support 6. You will learn later to decompose your code anyways. UI should be separate. Styling should be separate. Logic should be separate and etc... Warning: There is a bit of a learning curve with d3. Here is someone who wrote a TSP on a map. http://joneisen.me/d3-tsp-demo/ You can find his code here. It is not very complicated. https://github.com/yanatan16/d3-tsp-demo | ||
Deleted User 3420
24492 Posts
December 22 2016 18:06 GMT
#16373
2 - okay 3 - yeah it didn't seem nice. i missed where blisse talked about that, sorry blisse. I considred making a class for it myself but then didn't out of laziness. I'll use point. 4 - im not sure but i think I am going to end up using them a bunch more in there 5 - I have no idea what a lambda expression is. glancing at it now. it's a little confusing. I'll read about it later. 6 - oh duh yeah i could huh 7) I added it to the jframe not the jpanel, right? Is that what you meant ? I see where you are going with this. Sounds like a pain in the neck for a project like this, so I won't do that here. | ||
RoomOfMush
1296 Posts
December 22 2016 18:17 GMT
#16374
On December 23 2016 03:06 travis wrote: 4 - im not sure but i think I am going to end up using them a bunch more in there It is still better to use as many local variables as possible. Any state introduces potential for errors. Errors which might take a very long time to find and fix some time in the future. With local variables you have the added bonus of static code analysis by your compiler or IDE. Having fields for something that should be local means you might be using garbage data left from a previous invocation at some point. It is the same reasoning for your static field which we made non-static. Local variables might also give marginally better performance, but that is not quite important for you right now. On December 23 2016 03:06 travis wrote: 5 - I have no idea what a lambda expression is. glancing at it now. it's a little confusing. I'll read about it later. Lambda-Expressions are a feature introduced in Java8. They are just syntactic sugar to make anonymous inner classes which implement interfaces with only a single abstract method less verbose. In this particular piece of code we use them at 2 locations: 1) In the main method we pass a new instance of an annonymous class which implements "Runnable" to the "invokeLater" method of "EventQueue". 2) We implement "ActionListener" with as Lambdas which we pass to our JButtons. They do the same thing (functionally speaking) as the longer, written out version you had before. However there is a possibility for the compiler and the JIT to optimize lambdas better. On December 23 2016 03:06 travis wrote: 7) I added it to the jframe not the jpanel, right? Is that what you meant ? I see where you are going with this. Sounds like a pain in the neck for a project like this, so I won't do that here. You can not add anything to a JFrame. The JFrame has one Container (which is a superclass of JPanel) which it uses as its so called contentPane. When you call "add" on the JFrame the JFrame will delegate to its contentPane and just pass any parameters through. This means you really add to your ClickPanel instead because the ClickPanel is the contentPane for your JFrame. | ||
Acrofales
Spain17833 Posts
December 22 2016 18:30 GMT
#16375
| ||
meatpudding
Australia520 Posts
December 22 2016 22:35 GMT
#16376
| ||
FiWiFaKi
Canada9858 Posts
December 23 2016 04:09 GMT
#16377
I'm trying to create a Liquipedia page for a BW tournament I'd like to organize: http://wiki.teamliquid.net/starcraft/ShieldBattery_Showdown So everything is fine, I found a template that I'm trying to use to create an 8 by 8 round robin crosstable. So the issue is that originally, the template is created such that you enter team names, and then they'll be linked to a picture of their logo. Now this is all dandy, but I don't want the teams to link to anything, I would simply like to put players names in there, as well as fix the length of the cells (before this was a non-issue) since all logos were of the same size. So I looked around, and found the template on Liquipedia here: http://wiki.teamliquid.net/starcraft/Template:DetailedCrossTable I then clicked on edit on the top, and holy shit, so much code, and I don't know anything. What I'm trying to do is duplicate that template, and then edit it such that when I enter a Player's name, it will display only the name, and not redirect me to the image that it's trying to find in the picture directory. On top of that, it'd be a big plus if I could fix the length (or width I guess) of all the rows, instead of having them dynamically change with the length of name in the column. What would I need to do to achieve this as a programming super newbie? Please and thank you ![]() | ||
![]()
tofucake
Hyrule18968 Posts
December 23 2016 04:24 GMT
#16378
![]() | ||
FiWiFaKi
Canada9858 Posts
December 23 2016 04:26 GMT
#16379
On December 23 2016 13:24 tofucake wrote: You use layerCrossTable on Liquipedia" target="_blank" href="https://liquipedia.net/starcraft/Template ![]() ![]() ![]() Damn you Darking: "There are no templates with names instead of logos that I know of." Lol, thanks Tofucake. I finished setting it up already! You made it go from a 4 hour job to 15 minutes <3 | ||
3FFA
United States3931 Posts
December 24 2016 05:27 GMT
#16380
| ||
| ||
![]() StarCraft 2 mouzHeroMarine StarCraft: Brood War![]() IndyStarCraft ![]() UpATreeSC ![]() ViBE91 Railgan ![]() ForJumy ![]() ![]() PiGStarcraft30 DisKSc2 ![]() Stormgate Dota 2 League of Legends Counter-Strike Super Smash Bros Heroes of the Storm Other Games summit1g6830 ScreaM3331 FrodaN1926 Dendi1458 Beastyqt1175 B2W.Neo729 JuggernautJason448 elazer378 shahzam359 Livibee234 Trikslyr85 QueenE47 Organizations StarCraft 2 Other Games StarCraft 2 StarCraft: Brood War
StarCraft 2 • Adnapsc2 StarCraft: Brood War![]() • Hupsaiya ![]() • Laughngamez YouTube • AfreecaTV YouTube • sooper7s • intothetv ![]() • Kozan • Migwel ![]() • IndyKCrew ![]() • LaughNgamezSOOP Dota 2 League of Legends Other Games |
Replay Cast
SOOP
SKillous vs Spirit
Tenacious Turtle Tussle
PiG Sty Festival
Serral vs TriGGeR
Cure vs SHIN
The PondCast
Replay Cast
PiG Sty Festival
Clem vs Bunny
Solar vs Zoun
Replay Cast
Korean StarCraft League
PiG Sty Festival
herO vs Rogue
ByuN vs SKillous
[ Show More ] SC Evo Complete
[BSL 2025] Weekly
PiG Sty Festival
MaxPax vs Classic
Dark vs Maru
Sparkling Tuna Cup
|
|